From 6ea38bc90b417a1c2d3d6a9f0a00ce6f2f4e872e Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Fri, 29 Sep 2017 13:07:11 -0400 Subject: [PATCH] Got the basic migration framework working --- install/ajax/process-migration.php | 37 +++++++++++++++++++ install/migrations/AbstractMigration.php | 7 ++++ .../migrations/Pre140/StatusesMigration.php | 18 +++++++++ install/migrations/core.php | 4 +- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 install/ajax/process-migration.php create mode 100644 install/migrations/AbstractMigration.php create mode 100644 install/migrations/Pre140/StatusesMigration.php diff --git a/install/ajax/process-migration.php b/install/ajax/process-migration.php new file mode 100644 index 00000000..4b92687d --- /dev/null +++ b/install/ajax/process-migration.php @@ -0,0 +1,37 @@ + "{$file} not found!", 500)); + } +}); + +require(HESK_PATH . 'install/migrations/core.php'); + +$allMigrations = getAllMigrations(); +$json = file_get_contents('php://input'); +$request = json_decode($json, true); + +/* @var $migration AbstractMigration */ +$migration = $allMigrations[$request['migrationNumber']]; + +if ($request['direction'] === 'up') { + $migration->up(); +} elseif ($request['direction'] === 'down') { + $migration->down(); +} else { + output(array("message" => "Invalid direction provided"), 400); +} + +function output($data, $response = 200) { + http_response_code($response); + header('Content-Type: application/json'); + print json_encode($data); +} \ No newline at end of file diff --git a/install/migrations/AbstractMigration.php b/install/migrations/AbstractMigration.php new file mode 100644 index 00000000..e8212ad2 --- /dev/null +++ b/install/migrations/AbstractMigration.php @@ -0,0 +1,7 @@ + null + 1 => new StatusesMigration() ); } \ No newline at end of file