Format tools files

This commit is contained in:
Matthew Ross 2020-04-22 08:34:10 -04:00
parent c2575f08b0
commit dd08499be9
2 changed files with 534 additions and 532 deletions

View File

@ -2,251 +2,253 @@
error_reporting(E_ERROR); error_reporting(E_ERROR);
class TbGitHubImport { class TbGitHubImport {
var $db; var $db;
var $isNew; var $isNew;
var $user; var $user;
var $pass; var $pass;
var $repo; var $repo;
var $ch; var $ch;
var $api; var $api;
var $projects; var $projects;
function __construct() { function __construct() {
$this->ch = curl_init(); $this->ch = curl_init();
$this->api = "https://api.github.com/"; $this->api = "https://api.github.com/";
}
function __destruct() {
print "Closing 'taskboard.sqlite'...";
$this->db->exec('PRAGMA foreign_keys = ON');
$this->db->close();
print " Done.\n";
}
function import() {
$this->openDb();
$this->getInfo();
$this->loadData();
$this->importData();
}
private function openDb() {
print "Opening 'taskboard.sqlite'...";
$this->isNew = !file_exists('taskboard.sqlite');
if ($this->isNew) {
print "\n File not found, creating...";
} }
function __destruct() { $this->db = new SQLite3('taskboard.sqlite');
print "Closing 'taskboard.sqlite'..."; print " Done.\n";
$this->db->exec('PRAGMA foreign_keys = ON');
$this->db->close(); if ($this->isNew) {
print " Done.\n"; print "Creating tables...";
$schema = file_get_contents('schema');
$this->db->exec($schema);
print " Done.\n";
} }
function import() { $this->db->exec('PRAGMA foreign_keys = OFF');
$this->openDb(); }
$this->getInfo();
$this->loadData(); private function getInfo() {
$this->importData(); $this->user = readline("Enter your GitHub user name: ");
$this->pass = readline("Enter your GitHub password: ");
$this->repo = readline("What repo do you want to export projects from? ");
}
private function loadData() {
$options = array(
CURLOPT_URL => $this->api . "repos/" . $this->user . "/" . $this->repo . "/projects",
CURLOPT_USERAGENT => "Googlebot/2.1 (+http://www.google.com/bot.html)",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => $this->user . ":" . $this->pass,
CURLOPT_HTTPHEADER => array(
'Accept: application/vnd.github.inertia-preview+json'
)
);
curl_setopt_array($this->ch, $options);
$data = json_decode(curl_exec($this->ch));
$this->projects = [];
foreach ($data as $project) {
$this->projects[$project->id] =
(object)array("id" => $project->id, "name" => $project->name);
} }
private function openDb() { print("Found " . count($this->projects) . " project" .
print "Opening 'taskboard.sqlite'..."; (count($this->projects) === 1 ? "" : "s") . ".\n");
$this->isNew = !file_exists('taskboard.sqlite');
if ($this->isNew) { foreach ($this->projects as $project) {
print "\n File not found, creating..."; print " Loading Project " . $project->name . "...\n";
}
$this->db = new SQLite3('taskboard.sqlite'); curl_setopt(
print " Done.\n"; $this->ch,
CURLOPT_URL,
$this->api . "projects/" . $project->id . "/columns"
);
$data = json_decode(curl_exec($this->ch));
if ($this->isNew) { $colPos = 1;
print "Creating tables...";
$schema = file_get_contents('schema');
$this->db->exec($schema);
print " Done.\n";
}
$this->db->exec('PRAGMA foreign_keys = OFF'); foreach ($data as $column) {
} print " Loading Column " . $column->name . "...";
private function getInfo() { $currentColumn = (object)array(
$this->user = readline("Enter your GitHub user name: "); "id" => $column->id, "name" => $column->name, "position" => $colPos
$this->pass = readline("Enter your GitHub password: ");
$this->repo = readline("What repo do you want to export projects from? ");
}
private function loadData() {
$options = array(
CURLOPT_URL => $this->api . "repos/" . $this->user . "/" . $this->repo . "/projects",
CURLOPT_USERAGENT => "Googlebot/2.1 (+http://www.google.com/bot.html)",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => $this->user . ":" . $this->pass,
CURLOPT_HTTPHEADER => array(
'Accept: application/vnd.github.inertia-preview+json'
)
); );
curl_setopt_array($this->ch, $options); $colPos++;
$data = json_decode(curl_exec($this->ch)); curl_setopt(
$this->projects = []; $this->ch,
CURLOPT_URL,
$this->api . "projects/columns/" . $column->id . "/cards"
);
$cardData = json_decode(curl_exec($this->ch));
foreach ($data as $project) { $cards = [];
$this->projects[$project->id] = $cardPos = 1;
(object)array("id" => $project->id, "name" => $project->name);
foreach ($cardData as $card) {
$cards[] = (object)array(
"id" => $card->id,
"title" => "Imported",
"color" => "#ffffe0",
"description" => $card->note,
"position" => $cardPos,
"column_id" => $column->id
);
$cardPos++;
} }
print("Found " . count($this->projects) . " project" . $this->projects[$project->id]->columns[$column->id] = $currentColumn;
(count($this->projects) === 1 ? "" : "s") . ".\n"); $this->projects[$project->id]->columns[$column->id]->cards = $cards;
foreach ($this->projects as $project) { print " Loaded " . ($cardPos - 1) . " cards (tasks).\n";
print " Loading Project " . $project->name . "...\n"; }
curl_setopt( print " Loaded Project " . $project->name . ".\n";
$this->ch, }
CURLOPT_URL, }
$this->api . "projects/" . $project->id . "/columns"
);
$data = json_decode(curl_exec($this->ch));
$colPos = 1; private function importData() {
foreach ($this->projects as $project) {
print " Importing Project " . $project->name . "...\n";
foreach ($data as $column) { $exists = $this->db->querySingle('SELECT id FROM board WHERE name = "' .
print " Loading Column " . $column->name . "..."; $project->name . '"');
$currentColumn = (object)array( if (count($exists) === 0) {
"id" => $column->id, "name" => $column->name, "position" => $colPos $stmt = $this->db->prepare('INSERT INTO board (name, is_active) ' .
); 'VALUES (:name, :is_active)');
$colPos++;
curl_setopt( $stmt->bindValue(":name", $project->name);
$this->ch, $stmt->bindValue(":is_active", true);
CURLOPT_URL,
$this->api . "projects/columns/" . $column->id . "/cards"
);
$cardData = json_decode(curl_exec($this->ch));
$cards = []; if ($stmt->execute()) {
$cardPos = 1; print " Created board.\n";
foreach ($cardData as $card) {
$cards[] = (object)array(
"id" => $card->id,
"title" => "Imported",
"color" => "#ffffe0",
"description" => $card->note,
"position" => $cardPos,
"column_id" => $column->id
);
$cardPos++;
}
$this->projects[$project->id]->columns[$column->id] = $currentColumn;
$this->projects[$project->id]->columns[$column->id]->cards = $cards;
print " Loaded " . ($cardPos - 1) . " cards (tasks).\n";
}
print " Loaded Project " . $project->name . ".\n";
} }
}
if ($this->isNew) {
$stmt = $this->db->prepare('INSERT INTO user (username, security_level, ' .
'password_hash) VALUES (:uname, :secLev, :hash)');
$stmt->bindValue(':uname', 'admin');
$stmt->bindValue(':secLev', 1);
$stmt->bindValue(':hash', password_hash('admin', PASSWORD_BCRYPT));
if ($stmt->execute()) {
print " Created default admin user.\n";
}
$adminId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('INSERT INTO useroption (id, ' .
'new_tasks_at_bottom, show_animations, show_assignee, ' .
'multiple_tasks_per_row, language) VALUES (:id, :new, :anim, ' .
':assign, :mult, :lang)');
$stmt->bindValue(':id', $adminId);
$stmt->bindValue(':new', true);
$stmt->bindValue(':anim', true);
$stmt->bindValue(':assign', true);
$stmt->bindValue(':mult', false);
$stmt->bindValue(':lang', 'en');
$stmt->execute();
$optId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('UPDATE user SET user_option_id = ' . $optId .
' WHERE id = ' . $adminId);
$stmt->execute();
}
$boardId = $this->cleanupExistingTables($project->name);
$users = $this->db->query('SELECT id FROM user WHERE security_level = 1');
$stmt = $this->db->prepare('INSERT INTO board_user (user_id, board_id) '.
'VALUES (:user_id, :board_id)');
while ($user = $users->fetchArray()) {
$stmt->bindValue(':user_id', $user['id']);
$stmt->bindValue(':board_id', $boardId);
$stmt->execute();
}
print " Added admin user(s) to board.\n";
$colCount = 0;
$taskCount = 0;
foreach ($project->columns as $column) {
$stmt = $this->db->prepare('INSERT INTO column (name, position, board_id) ' .
'VALUES (:name, :pos, :board_id)');
$stmt->bindValue(':name', $column->name);
$stmt->bindValue(':pos', $column->position);
$stmt->bindValue(':board_id', $boardId);
$stmt->execute();
$colCount++;
$colId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('INSERT INTO task (title, description, ' .
'color, position, column_id) VALUES (:title, :description, :color,' .
':pos, :col_id)');
foreach ($column->cards as $card) {
$stmt->bindValue(':title', $card->title);
$stmt->bindValue(':description', $card->description);
$stmt->bindValue(':color', $card->color);
$stmt->bindValue(':pos', $card->position);
$stmt->bindValue(':col_id', $colId);
$stmt->execute();
$taskCount++;
}
}
print " Inserted " . $colCount . " columns, and " . $taskCount . " tasks.\n";
} }
private function importData() { print " Done Importing.\n";
foreach ($this->projects as $project) { }
print " Importing Project " . $project->name . "...\n";
$exists = $this->db->querySingle('SELECT id FROM board WHERE name = "' . private function cleanupExistingTables($boardName) {
$project->name . '"'); $boardId = $this->db->querySingle('SELECT id FROM board ' .
'WHERE name = "' . $boardName . '"');
$this->db->exec('DELETE FROM board_user WHERE board_id = ' . $boardId);
$columns = $this->db->query('SELECT id FROM column WHERE board_id = ' . $boardId);
if (count($exists) === 0) { if ($columns) {
$stmt = $this->db->prepare('INSERT INTO board (name, is_active) ' . while ($col = $columns->fetchArray()) {
'VALUES (:name, :is_active)'); $this->db->exec('DELETE FROM task WHERE column_id = ' . $col['id']);
}
$stmt->bindValue(":name", $project->name);
$stmt->bindValue(":is_active", true);
if ($stmt->execute()) {
print " Created board.\n";
}
}
if ($this->isNew) {
$stmt = $this->db->prepare('INSERT INTO user (username, security_level, ' .
'password_hash) VALUES (:uname, :secLev, :hash)');
$stmt->bindValue(':uname', 'admin');
$stmt->bindValue(':secLev', 1);
$stmt->bindValue(':hash', password_hash('admin', PASSWORD_BCRYPT));
if ($stmt->execute()) {
print " Created default admin user.\n";
}
$adminId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('INSERT INTO useroption (id, ' .
'new_tasks_at_bottom, show_animations, show_assignee, ' .
'multiple_tasks_per_row, language) VALUES (:id, :new, :anim, ' .
':assign, :mult, :lang)');
$stmt->bindValue(':id', $adminId);
$stmt->bindValue(':new', true);
$stmt->bindValue(':anim', true);
$stmt->bindValue(':assign', true);
$stmt->bindValue(':mult', false);
$stmt->bindValue(':lang', 'en');
$stmt->execute();
$optId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('UPDATE user SET user_option_id = ' . $optId .
' WHERE id = ' . $adminId);
$stmt->execute();
}
$boardId = $this->cleanupExistingTables($project->name);
$users = $this->db->query('SELECT id FROM user WHERE security_level = 1');
$stmt = $this->db->prepare('INSERT INTO board_user (user_id, board_id) '.
'VALUES (:user_id, :board_id)');
while ($user = $users->fetchArray()) {
$stmt->bindValue(':user_id', $user['id']);
$stmt->bindValue(':board_id', $boardId);
$stmt->execute();
}
print " Added admin user(s) to board.\n";
$colCount = 0;
$taskCount = 0;
foreach ($project->columns as $column) {
$stmt = $this->db->prepare('INSERT INTO column (name, position, board_id) ' .
'VALUES (:name, :pos, :board_id)');
$stmt->bindValue(':name', $column->name);
$stmt->bindValue(':pos', $column->position);
$stmt->bindValue(':board_id', $boardId);
$stmt->execute();
$colCount++;
$colId = $this->db->lastInsertRowID();
$stmt = $this->db->prepare('INSERT INTO task (title, description, ' .
'color, position, column_id) VALUES (:title, :description, :color,' .
':pos, :col_id)');
foreach ($column->cards as $card) {
$stmt->bindValue(':title', $card->title);
$stmt->bindValue(':description', $card->description);
$stmt->bindValue(':color', $card->color);
$stmt->bindValue(':pos', $card->position);
$stmt->bindValue(':col_id', $colId);
$stmt->execute();
$taskCount++;
}
}
print " Inserted " . $colCount . " columns, and " . $taskCount . " tasks.\n";
}
print " Done Importing.\n";
} }
private function cleanupExistingTables($boardName) { $this->db->exec('DELETE FROM column WHERE board_id = ' . $boardId);
$boardId = $this->db->querySingle('SELECT id FROM board ' .
'WHERE name = "' . $boardName . '"');
$this->db->exec('DELETE FROM board_user WHERE board_id = ' . $boardId);
$columns = $this->db->query('SELECT id FROM column WHERE board_id = ' . $boardId);
while ($col = $columns->fetchArray()) { return $boardId;
$this->db->exec('DELETE FROM task WHERE column_id = ' . $col['id']); }
}
$this->db->exec('DELETE FROM column WHERE board_id = ' . $boardId);
return $boardId;
}
} }

View File

@ -1,359 +1,359 @@
<?php <?php
class TbMigrate { class TbMigrate {
var $oldDb; var $oldDb;
var $newDb; var $newDb;
function __construct() { function __construct() {
print "Opening 'taskboard.db'..."; print "Opening 'taskboard.db'...";
try { try {
$this->oldDb = new SQLite3('taskboard.db', SQLITE3_OPEN_READONLY); $this->oldDb = new SQLite3('taskboard.db', SQLITE3_OPEN_READONLY);
print "\t\tDone.\n"; print "\t\tDone.\n";
} catch (Exception $e) { } catch (Exception $e) {
print "\t\tError opening 'taskboard.db'\n"; print "\t\tError opening 'taskboard.db'\n";
print " " . $e->getMessage() . "\n"; print " " . $e->getMessage() . "\n";
return; return;
}
print "Opening 'taskboard.sqlite'...";
try {
unlink('taskboard.sqlite'); // Always start fresh.
$this->newDb = new SQLite3('taskboard.sqlite');
print "\t\tDone.\n\n";
} catch (Exception $e) {
print "\t\tError creating 'taskboard.sqlite'\n";
print " " . $e->getMessage() . "\n";
return;
}
} }
function __destruct() { print "Opening 'taskboard.sqlite'...";
print "\n"; try {
print "Closing 'taskboard.sqlite'..."; unlink('taskboard.sqlite'); // Always start fresh.
$this->newDb->exec('PRAGMA foreign_keys = ON');
$this->newDb->close();
print "\t\tDone.\n";
print "Closing 'taskboard.db'..."; $this->newDb = new SQLite3('taskboard.sqlite');
$this->oldDb->close(); print "\t\tDone.\n\n";
print "\t\tDone.\n"; } catch (Exception $e) {
print "\t\tError creating 'taskboard.sqlite'\n";
print " " . $e->getMessage() . "\n";
return;
}
}
function __destruct() {
print "\n";
print "Closing 'taskboard.sqlite'...";
$this->newDb->exec('PRAGMA foreign_keys = ON');
$this->newDb->close();
print "\t\tDone.\n";
print "Closing 'taskboard.db'...";
$this->oldDb->close();
print "\t\tDone.\n";
}
function migrate() {
$this->createTables();
$this->migrateActivity();
// TODO: attachments table
$this->migrateAutoAction();
$this->migrateBoard();
$this->migrateBoardUser();
$this->migrateCategory();
$this->migrateCollapsed();
$this->migrateComment();
$this->migrateItem();
$this->migrateLane();
$this->migrateUser();
}
private function createTables() {
print " Creating new tables...";
$schema = file_get_contents('schema');
$this->newDb->exec($schema);
$this->newDb->exec('PRAGMA foreign_keys = OFF');
print "\t\t\tDone.\n\n";
}
private function getItemType($str) {
if (strpos($str, 'item') !== false) {
return 'task';
} }
function migrate() { if (strpos($str, 'column') !== false) {
$this->createTables(); return 'column';
$this->migrateActivity();
// TODO: attachments table
$this->migrateAutoAction();
$this->migrateBoard();
$this->migrateBoardUser();
$this->migrateCategory();
$this->migrateCollapsed();
$this->migrateComment();
$this->migrateItem();
$this->migrateLane();
$this->migrateUser();
} }
private function createTables() { if (strpos($str, 'board') !== false) {
print " Creating new tables..."; return 'board';
$schema = file_get_contents('schema');
$this->newDb->exec($schema);
$this->newDb->exec('PRAGMA foreign_keys = OFF');
print "\t\t\tDone.\n\n";
} }
private function getItemType($str) { if (strpos($str, 'changed') !== false || strpos($str, 'logged') !== false ||
if (strpos($str, 'item') !== false) { strpos($str, 'added') !== false || strpos($str, 'removed') !== false) {
return 'task'; return 'user';
}
if (strpos($str, 'column') !== false) {
return 'column';
}
if (strpos($str, 'board') !== false) {
return 'board';
}
if (strpos($str, 'changed') !== false || strpos($str, 'logged') !== false ||
strpos($str, 'added') !== false || strpos($str, 'removed') !== false) {
return 'user';
}
return null;
} }
private function getItemId($itemId, $newValue) { return null;
if (isset($itemId)) { }
return $itemId;
}
$obj = json_decode($newValue); private function getItemId($itemId, $newValue) {
if (isset($itemId)) {
if ($obj !== null) { return $itemId;
return $obj->id;
}
return null;
} }
private function getActionType($row) { $obj = json_decode($newValue);
switch ($row['action_id']) {
case 0: if ($obj !== null) {
return 1; return $obj->id;
break;
case 2:
return 4;
break;
case 3:
return 6;
break;
default:
return null;
}
} }
private function getActionChange($row) { return null;
if (isset($row['color'])) { }
return $row['color'];
}
if (isset($row['category_id'])) { private function getActionType($row) {
return $row['category_id']; switch ($row['action_id']) {
} case 0:
return 1;
break;
case 2:
return 4;
break;
case 3:
return 6;
break;
default:
return null;
}
}
if (isset($row['assignee_id'])) { private function getActionChange($row) {
return $row['assignee_id']; if (isset($row['color'])) {
} return $row['color'];
return null;
} }
private function migrateTable($stmtStr, $fn, $oldTable = null) { if (isset($row['category_id'])) {
$table = isset($oldTable) ? $oldTable : explode(' ', $stmtStr)[2]; return $row['category_id'];
print " Migrating table `$table`...";
$results = $this->oldDb->query("SELECT * from $table ORDER BY id");
if ($results->numColumns() === 0) {
print " no rows.\n";
return;
}
$stmt = $this->newDb->prepare($stmtStr);
$rowCount = 0;
$errCount = 0;
while ($row = $results->fetchArray()) {
$fn($stmt, $row);
if ($stmt->execute() === false) {
$errCount++;
continue;
}
$rowCount++;
}
$stmt->close();
print strlen($table) < 10 ? "\t" : "";
print "\t$rowCount rows migrated.\n";
if ($errCount > 0) {
print " $errCount rows failed.\n";
}
} }
private function migrateActivity() { if (isset($row['assignee_id'])) {
$stmtStr = 'INSERT INTO activity (id, user_id, log_text, before, after, ' . return $row['assignee_id'];
'item_type, item_id, timestamp) VALUES (:id, :user_id, :log_text, ' .
':before, :after, :item_type, :item_id, :timestamp)';
$knownNames = [];
$this->migrateTable($stmtStr, function(&$stmt, $row) use ($knownNames) {
$name = explode(' ', $row['comment'])[0];
if (!array_key_exists($name, $knownNames)) {
$usr = $this->oldDb->query('SELECT id FROM user ' .
'WHERE username = "' . $name . '"');
$knownNames[$name] = $usr->fetchArray()['id'];
}
$type = $this->getItemType($row['comment']);
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':user_id', $knownNames[$name]);
$stmt->bindValue(':log_text', $row['comment']);
$stmt->bindValue(':before', $row['old_value']);
$stmt->bindValue(':after', $row['new_value']);
$stmt->bindValue(':item_type', $type);
$stmt->bindValue(':item_id', $type === 'user'
? $knownNames[$name]
: $this->getItemId($row['item_id'], $row['new_value']));
$stmt->bindValue(':timestamp', $row['timestamp']);
});
} }
private function migrateAutoAction() { return null;
$stmtStr = 'INSERT INTO autoaction (id, trigger, source_id, type, ' . }
'change_to, board_id) VALUES (:id, :trigger, :source_id, :type, ' .
':change_to, :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) { private function migrateTable($stmtStr, $fn, $oldTable = null) {
$stmt->bindValue(':id', $row['id']); $table = isset($oldTable) ? $oldTable : explode(' ', $stmtStr)[2];
$stmt->bindValue(':trigger', ((int)$row['trigger_id']) + 1);
$stmt->bindValue(':source_id', $row['secondary_id']); print " Migrating table `$table`...";
$stmt->bindValue(':type', $this->getActionType($row));
$stmt->bindValue(':change_to', $this->getActionChange($row)); $results = $this->oldDb->query("SELECT * from $table ORDER BY id");
$stmt->bindValue(':board_id', $row['board_id']);
}); if ($results->numColumns() === 0) {
print " no rows.\n";
return;
} }
private function migrateBoard() { $stmt = $this->newDb->prepare($stmtStr);
$stmtStr = 'INSERT INTO board (id, name, is_active) ' . $rowCount = 0;
'VALUES (:id, :name, :is_active)'; $errCount = 0;
$this->migrateTable($stmtStr, function (&$stmt, $row) { while ($row = $results->fetchArray()) {
$stmt->bindValue(':id', $row['id']); $fn($stmt, $row);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':is_active', $row['active']); if ($stmt->execute() === false) {
}); $errCount++;
continue;
}
$rowCount++;
} }
private function migrateBoardUser() { $stmt->close();
$stmtStr = 'INSERT INTO board_user (id, user_id, board_id) ' . print strlen($table) < 10 ? "\t" : "";
'VALUES (:id, :user_id, :board_id)'; print "\t$rowCount rows migrated.\n";
$this->migrateTable($stmtStr, function (&$stmt, $row) { if ($errCount > 0) {
$stmt->bindValue(':id', $row['id']); print " $errCount rows failed.\n";
$stmt->bindValue(':user_id', $row['user_id']); }
$stmt->bindValue(':board_id', $row['board_id']); }
});
private function migrateActivity() {
$stmtStr = 'INSERT INTO activity (id, user_id, log_text, before, after, ' .
'item_type, item_id, timestamp) VALUES (:id, :user_id, :log_text, ' .
':before, :after, :item_type, :item_id, :timestamp)';
$knownNames = [];
$this->migrateTable($stmtStr, function(&$stmt, $row) use ($knownNames) {
$name = explode(' ', $row['comment'])[0];
if (!array_key_exists($name, $knownNames)) {
$usr = $this->oldDb->query('SELECT id FROM user ' .
'WHERE username = "' . $name . '"');
$knownNames[$name] = $usr->fetchArray()['id'];
}
$type = $this->getItemType($row['comment']);
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':user_id', $knownNames[$name]);
$stmt->bindValue(':log_text', $row['comment']);
$stmt->bindValue(':before', $row['old_value']);
$stmt->bindValue(':after', $row['new_value']);
$stmt->bindValue(':item_type', $type);
$stmt->bindValue(':item_id', $type === 'user'
? $knownNames[$name]
: $this->getItemId($row['item_id'], $row['new_value']));
$stmt->bindValue(':timestamp', $row['timestamp']);
});
}
private function migrateAutoAction() {
$stmtStr = 'INSERT INTO autoaction (id, trigger, source_id, type, ' .
'change_to, board_id) VALUES (:id, :trigger, :source_id, :type, ' .
':change_to, :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':trigger', ((int)$row['trigger_id']) + 1);
$stmt->bindValue(':source_id', $row['secondary_id']);
$stmt->bindValue(':type', $this->getActionType($row));
$stmt->bindValue(':change_to', $this->getActionChange($row));
$stmt->bindValue(':board_id', $row['board_id']);
});
}
private function migrateBoard() {
$stmtStr = 'INSERT INTO board (id, name, is_active) ' .
'VALUES (:id, :name, :is_active)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':is_active', $row['active']);
});
}
private function migrateBoardUser() {
$stmtStr = 'INSERT INTO board_user (id, user_id, board_id) ' .
'VALUES (:id, :user_id, :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':user_id', $row['user_id']);
$stmt->bindValue(':board_id', $row['board_id']);
});
}
private function migrateCategory() {
$stmtStr = 'INSERT INTO category (id, name, default_task_color, board_id) ' .
'VALUES (:id, :name, "#ffffe0", :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':board_id', $row['board_id']);
});
}
private function migrateCollapsed() {
$stmtStr = 'INSERT INTO collapsed (id, user_id, column_id) ' .
'VALUES (:id, :user_id, :column_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':user_id', $row['user_id']);
$stmt->bindValue(':column_id', $row['lane_id']);
});
}
private function migrateComment() {
$stmtStr = 'INSERT INTO comment (id, text, user_id, task_id, timestamp, ' .
'is_edited) VALUES (:id, :text, :user_id, :task_id, :timestamp, 0)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':text', $row['text']);
$stmt->bindValue(':user_id', $row['user_id']);
$stmt->bindValue(':task_id', $row['item_id']);
$stmt->bindValue(':timestamp', $row['timestamp']);
});
}
private function migrateItem() {
$stmtStr = 'INSERT INTO task (id, title, description, color, due_date, ' .
'points, position, column_id) VALUES (:id, :title, :description, :color, ' .
':due_date, :points, :position, :column_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':title', $row['title']);
$stmt->bindValue(':description', $row['description']);
$stmt->bindValue(':color', $row['color']);
$stmt->bindValue(':due_date', $row['due_date']);
$stmt->bindValue(':points', $row['points']);
$stmt->bindValue(':position', $row['position']);
$stmt->bindValue(':column_id', $row['lane_id']);
$this->newDb->exec('INSERT INTO task_user (user_id, task_id) ' .
'VALUES (' . $row['assignee'] . ', ' . $row['id'] . ')');
$this->newDb->exec('INSERT INTO category_task (category_id, task_id) ' .
'VALUES (' . $row['category'] . ', ' . $row['id'] . ')');
}, 'item');
}
private function migrateLane() {
$stmtStr = 'INSERT INTO column (id, name, position, board_id) ' .
'VALUES (:id, :name, :position, :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':position', $row['position']);
$stmt->bindValue(':board_id', $row['board_id']);
}, 'lane');
}
private function migrateUser() {
$stmtStr = 'INSERT INTO user (id, username, security_level, password_hash, ' .
'email, default_board_id, user_option_id, last_login) VALUES (:id, ' .
':uname, :secLev, :hash, :email, :board, :option, :last)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':uname', $row['username']);
$stmt->bindValue(':secLev', $row['is_admin'] === 1 ? 1 : 3);
$stmt->bindValue(':hash', $row['password']);
$stmt->bindValue(':email', $row['email']);
$stmt->bindValue(':board', $row['default_board']);
$stmt->bindValue(':option', $row['id']);
$stmt->bindValue(':last', $row['last_login']);
});
$users = $this->newDb->query('SELECT id FROM user ORDER BY id');
while ($row = $users->fetchArray()) {
$stmt = $this->newDb->prepare('INSERT INTO useroption (id, ' .
'new_tasks_at_bottom, show_animations, show_assignee, ' .
'multiple_tasks_per_row, language) VALUES (:id, :atBottom, :anims, ' .
':assignee, 0, "en")');
$opts = $this->oldDb->query(
'SELECT * FROM option WHERE id = ' . (int)$row['id']
);
$opts = $opts->fetchArray();
if ($opts === false) {
continue;
}
$stmt->bindValue(':id', $opts['id']);
$stmt->bindValue(':atBottom', isset($opts['tasks_order'])
? $opts['tasks_order']
: $opts['new_task_position']);
$stmt->bindValue(':anims', isset($opts['animate'])
? $opts['animate']
: $opts['show_animations']);
$stmt->bindValue(':assignee', isset($opts['show_assignee'])
? $opts['show_assignee']
: 1);
$stmt->execute();
} }
private function migrateCategory() { $stmt->close();
$stmtStr = 'INSERT INTO category (id, name, default_task_color, board_id) ' . }
'VALUES (:id, :name, "#ffffe0", :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':board_id', $row['board_id']);
});
}
private function migrateCollapsed() {
$stmtStr = 'INSERT INTO collapsed (id, user_id, column_id) ' .
'VALUES (:id, :user_id, :column_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':user_id', $row['user_id']);
$stmt->bindValue(':column_id', $row['lane_id']);
});
}
private function migrateComment() {
$stmtStr = 'INSERT INTO comment (id, text, user_id, task_id, timestamp, ' .
'is_edited) VALUES (:id, :text, :user_id, :task_id, :timestamp, 0)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':text', $row['text']);
$stmt->bindValue(':user_id', $row['user_id']);
$stmt->bindValue(':task_id', $row['item_id']);
$stmt->bindValue(':timestamp', $row['timestamp']);
});
}
private function migrateItem() {
$stmtStr = 'INSERT INTO task (id, title, description, color, due_date, ' .
'points, position, column_id) VALUES (:id, :title, :description, :color, ' .
':due_date, :points, :position, :column_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':title', $row['title']);
$stmt->bindValue(':description', $row['description']);
$stmt->bindValue(':color', $row['color']);
$stmt->bindValue(':due_date', $row['due_date']);
$stmt->bindValue(':points', $row['points']);
$stmt->bindValue(':position', $row['position']);
$stmt->bindValue(':column_id', $row['lane_id']);
$this->newDb->exec('INSERT INTO task_user (user_id, task_id) ' .
'VALUES (' . $row['assignee'] . ', ' . $row['id'] . ')');
$this->newDb->exec('INSERT INTO category_task (category_id, task_id) ' .
'VALUES (' . $row['category'] . ', ' . $row['id'] . ')');
}, 'item');
}
private function migrateLane() {
$stmtStr = 'INSERT INTO column (id, name, position, board_id) ' .
'VALUES (:id, :name, :position, :board_id)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':name', $row['name']);
$stmt->bindValue(':position', $row['position']);
$stmt->bindValue(':board_id', $row['board_id']);
}, 'lane');
}
private function migrateUser() {
$stmtStr = 'INSERT INTO user (id, username, security_level, password_hash, ' .
'email, default_board_id, user_option_id, last_login) VALUES (:id, ' .
':uname, :secLev, :hash, :email, :board, :option, :last)';
$this->migrateTable($stmtStr, function (&$stmt, $row) {
$stmt->bindValue(':id', $row['id']);
$stmt->bindValue(':uname', $row['username']);
$stmt->bindValue(':secLev', $row['is_admin'] === 1 ? 1 : 3);
$stmt->bindValue(':hash', $row['password']);
$stmt->bindValue(':email', $row['email']);
$stmt->bindValue(':board', $row['default_board']);
$stmt->bindValue(':option', $row['id']);
$stmt->bindValue(':last', $row['last_login']);
});
$users = $this->newDb->query('SELECT id FROM user ORDER BY id');
while ($row = $users->fetchArray()) {
$stmt = $this->newDb->prepare('INSERT INTO useroption (id, ' .
'new_tasks_at_bottom, show_animations, show_assignee, ' .
'multiple_tasks_per_row, language) VALUES (:id, :atBottom, :anims, ' .
':assignee, 0, "en")');
$opts = $this->oldDb->query(
'SELECT * FROM option WHERE id = ' . (int)$row['id']
);
$opts = $opts->fetchArray();
if ($opts === false) {
continue;
}
$stmt->bindValue(':id', $opts['id']);
$stmt->bindValue(':atBottom', isset($opts['tasks_order'])
? $opts['tasks_order']
: $opts['new_task_position']);
$stmt->bindValue(':anims', isset($opts['animate'])
? $opts['animate']
: $opts['show_animations']);
$stmt->bindValue(':assignee', isset($opts['show_assignee'])
? $opts['show_assignee']
: 1);
$stmt->execute();
}
$stmt->close();
}
} }