Got the basic migration framework working

master
Mike Koch 7 years ago
parent dbf9baca75
commit 6ea38bc90b
No known key found for this signature in database
GPG Key ID: 9BA5D7F8391455ED

@ -0,0 +1,37 @@
<?php
define('IN_SCRIPT', 1);
define('HESK_PATH', '../../');
spl_autoload_register(function ($class) {
// USED FOR MIGRATIONS
$file = HESK_PATH . 'install/migrations/' . str_replace('\\', '/', $class) . '.php';
if (file_exists($file)) {
require($file);
} else {
output(array("message" => "{$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);
}

@ -0,0 +1,7 @@
<?php
abstract class AbstractMigration {
abstract function up();
abstract function down();
}

@ -0,0 +1,18 @@
<?php
namespace Pre140;
use AbstractMigration;
class StatusesMigration extends AbstractMigration {
function up() {
// TODO: Implement up() method.
die('up called');
}
function down() {
// TODO: Implement down() method.
die('down called');
}
}

@ -1,7 +1,9 @@
<?php
use Pre140\StatusesMigration;
function getAllMigrations() {
return array(
1 => null
1 => new StatusesMigration()
);
}
Loading…
Cancel
Save