Got the basic migration framework working
This commit is contained in:
parent
dbf9baca75
commit
6ea38bc90b
37
install/ajax/process-migration.php
Normal file
37
install/ajax/process-migration.php
Normal file
@ -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);
|
||||||
|
}
|
7
install/migrations/AbstractMigration.php
Normal file
7
install/migrations/AbstractMigration.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class AbstractMigration {
|
||||||
|
abstract function up();
|
||||||
|
|
||||||
|
abstract function down();
|
||||||
|
}
|
18
install/migrations/Pre140/StatusesMigration.php
Normal file
18
install/migrations/Pre140/StatusesMigration.php
Normal file
@ -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
|
<?php
|
||||||
|
|
||||||
|
use Pre140\StatusesMigration;
|
||||||
|
|
||||||
function getAllMigrations() {
|
function getAllMigrations() {
|
||||||
return array(
|
return array(
|
||||||
1 => null
|
1 => new StatusesMigration()
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user