2014-12-31 01:33:56 +01:00
|
|
|
<?php
|
|
|
|
use Framadate\Migration\From_0_8_to_0_9_Migration;
|
|
|
|
use Framadate\Migration\Migration;
|
|
|
|
use Framadate\Utils;
|
|
|
|
|
|
|
|
include_once __DIR__ . '/app/inc/init.php';
|
|
|
|
|
|
|
|
function output($msg) {
|
|
|
|
echo $msg . '<br/>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// List a Migration sub classes to execute
|
|
|
|
$migrations = [
|
|
|
|
new From_0_8_to_0_9_Migration()
|
|
|
|
];
|
2014-12-31 14:02:36 +01:00
|
|
|
// ---------------------------------------
|
2014-12-31 01:33:56 +01:00
|
|
|
|
|
|
|
// Check if MIGRATION_TABLE already exists
|
|
|
|
$tables = $connect->allTables();
|
|
|
|
$pdo = $connect->getPDO();
|
|
|
|
|
|
|
|
if (!in_array(MIGRATION_TABLE, $tables)) {
|
|
|
|
$pdo->exec('
|
|
|
|
CREATE TABLE IF NOT EXISTS `' . MIGRATION_TABLE . '` (
|
|
|
|
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
|
`name` TEXT NOT NULL,
|
|
|
|
`execute_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (`id`)
|
|
|
|
)
|
|
|
|
ENGINE = MyISAM
|
|
|
|
DEFAULT CHARSET = utf8;');
|
|
|
|
|
|
|
|
output('Table ' . MIGRATION_TABLE . ' created.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$selectStmt = $pdo->prepare('SELECT id FROM ' . MIGRATION_TABLE . ' WHERE name=?');
|
|
|
|
$insertStmt = $pdo->prepare('INSERT INTO ' . MIGRATION_TABLE . ' (name) VALUES (?)');
|
2014-12-31 14:02:36 +01:00
|
|
|
$countSucceeded = 0;
|
|
|
|
$countFailed = 0;
|
|
|
|
$countSkipped = 0;
|
2014-12-31 01:33:56 +01:00
|
|
|
|
|
|
|
// Loop on every Migration sub classes
|
|
|
|
foreach ($migrations as $migration) {
|
|
|
|
$className = get_class($migration);
|
|
|
|
|
|
|
|
// Check if $className is a Migration sub class
|
|
|
|
if (!$migration instanceof Migration) {
|
2014-12-31 14:02:36 +01:00
|
|
|
output('The class ' . $className . ' is not a sub class of Framadate\\Migration\\Migration.');
|
2014-12-31 01:33:56 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the Migration is already executed
|
|
|
|
$selectStmt->execute([$className]);
|
|
|
|
$executed = $selectStmt->rowCount();
|
|
|
|
$selectStmt->closeCursor();
|
|
|
|
|
|
|
|
if (!$executed) {
|
|
|
|
$migration->execute($pdo);
|
2014-12-31 14:02:36 +01:00
|
|
|
if ($insertStmt->execute([$className])) {
|
|
|
|
$countSucceeded++;
|
|
|
|
output('Migration done: ' . $className);
|
|
|
|
} else {
|
|
|
|
$countFailed++;
|
|
|
|
output('Migration failed: ' . $className);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$countSkipped++;
|
2014-12-31 01:33:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-12-31 14:02:36 +01:00
|
|
|
|
|
|
|
$countTotal = $countSucceeded + $countFailed + $countSkipped;
|
|
|
|
|
|
|
|
output('Summary<hr/>');
|
|
|
|
output('Success: ' . $countSucceeded . ' / ' . $countTotal);
|
|
|
|
output('Fail: ' . $countFailed . ' / ' . $countTotal);
|
|
|
|
output('Skipped: ' . $countSkipped . ' / ' . $countTotal);
|