From de128dbad860478496a0d655b5eb5c1005ebbabe Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 18 Feb 2017 09:42:01 -0500 Subject: Remove default swimlane --- app/Schema/Migration.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 app/Schema/Migration.php (limited to 'app/Schema/Migration.php') diff --git a/app/Schema/Migration.php b/app/Schema/Migration.php new file mode 100644 index 00000000..395ac1ad --- /dev/null +++ b/app/Schema/Migration.php @@ -0,0 +1,63 @@ +prepare('INSERT INTO swimlanes (project_id, name, is_active, position) VALUES (?, ?, ?, ?)'); + $rq->execute(array( + $project['id'], + $project['default_swimlane'], + (int) $project['show_default_swimlane'], + $project['show_default_swimlane'] == 1 ? 1 : 0, + )); + + $swimlaneId = get_last_insert_id($pdo); + + // Reorder swimlanes if the default one was active + if ($project['show_default_swimlane']) { + $rq = $pdo->prepare("UPDATE swimlanes SET position=position+1 WHERE project_id=? AND is_active='1' AND id!=?"); + $rq->execute(array( + $project['id'], + $swimlaneId, + )); + } + + // Move all tasks to new swimlane + $rq = $pdo->prepare("UPDATE tasks SET swimlane_id=? WHERE swimlane_id='0' AND project_id=?"); + $rq->execute(array( + $swimlaneId, + $project['id'], + )); + + // Migrate automatic actions + $rq = $pdo->prepare("UPDATE action_has_params SET value=? WHERE id IN (SELECT action_has_params.id FROM action_has_params LEFT JOIN actions ON actions.id=action_has_params.action_id WHERE project_id=? AND name='swimlane_id' AND value='0')"); + $rq->execute(array($swimlaneId, $project['id'])); + } +} + +function get_all_projects(PDO $pdo) +{ + $rq = $pdo->prepare('SELECT * FROM projects'); + $rq->execute(); + return $rq->fetchAll(PDO::FETCH_ASSOC); +} + +function get_last_insert_id(PDO $pdo) +{ + if (DB_DRIVER === 'postgres') { + $rq = $pdo->prepare('SELECT LASTVAL()'); + $rq->execute(); + return $rq->fetchColumn(); + } + + return $pdo->lastInsertId(); +} + -- cgit v1.2.3