Migration: Add summary at the end of the execution

This commit is contained in:
Olivier PEREZ 2014-12-31 14:02:36 +01:00
parent 88cae82e71
commit 64a017a44c

View File

@ -11,9 +11,9 @@ function output($msg) {
// List a Migration sub classes to execute // List a Migration sub classes to execute
$migrations = [ $migrations = [
new From_0_8_to_0_9_Migration(),
new From_0_8_to_0_9_Migration() new From_0_8_to_0_9_Migration()
]; ];
// ---------------------------------------
// Check if MIGRATION_TABLE already exists // Check if MIGRATION_TABLE already exists
$tables = $connect->allTables(); $tables = $connect->allTables();
@ -35,6 +35,9 @@ CREATE TABLE IF NOT EXISTS `' . MIGRATION_TABLE . '` (
$selectStmt = $pdo->prepare('SELECT id FROM ' . MIGRATION_TABLE . ' WHERE name=?'); $selectStmt = $pdo->prepare('SELECT id FROM ' . MIGRATION_TABLE . ' WHERE name=?');
$insertStmt = $pdo->prepare('INSERT INTO ' . MIGRATION_TABLE . ' (name) VALUES (?)'); $insertStmt = $pdo->prepare('INSERT INTO ' . MIGRATION_TABLE . ' (name) VALUES (?)');
$countSucceeded = 0;
$countFailed = 0;
$countSkipped = 0;
// Loop on every Migration sub classes // Loop on every Migration sub classes
foreach ($migrations as $migration) { foreach ($migrations as $migration) {
@ -42,7 +45,7 @@ foreach ($migrations as $migration) {
// Check if $className is a Migration sub class // Check if $className is a Migration sub class
if (!$migration instanceof Migration) { if (!$migration instanceof Migration) {
output('The class '. $className . ' is not a sub class of Framadate\\Migration\\Migration.'); output('The class ' . $className . ' is not a sub class of Framadate\\Migration\\Migration.');
exit; exit;
} }
@ -53,8 +56,22 @@ foreach ($migrations as $migration) {
if (!$executed) { if (!$executed) {
$migration->execute($pdo); $migration->execute($pdo);
$insertStmt->execute([$className]); if ($insertStmt->execute([$className])) {
output('Migration done: ' . $className); $countSucceeded++;
output('Migration done: ' . $className);
} else {
$countFailed++;
output('Migration failed: ' . $className);
}
} else {
$countSkipped++;
} }
} }
$countTotal = $countSucceeded + $countFailed + $countSkipped;
output('Summary<hr/>');
output('Success: ' . $countSucceeded . ' / ' . $countTotal);
output('Fail: ' . $countFailed . ' / ' . $countTotal);
output('Skipped: ' . $countSkipped . ' / ' . $countTotal);