mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 08:34:39 +00:00
MVC/model migrations, show error message in run_migrations.php when migration fails.
This commit is contained in:
parent
62fa8b5d66
commit
7092d3c782
@ -578,6 +578,7 @@ abstract class BaseModel
|
||||
* The BaseModelMigration class should be named with the corresponding version
|
||||
* prefixed with an M and . replaced by _ for example : M1_0_1 equals version 1.0.1
|
||||
*
|
||||
* @return bool status (true-->success, false-->failed)
|
||||
*/
|
||||
public function runMigrations()
|
||||
{
|
||||
@ -638,8 +639,11 @@ abstract class BaseModel
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$logger->error("Model ".$class_info->getName() ." can't be saved, skip ( " .$e . " )");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,14 +53,18 @@ foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($model_dir
|
||||
if ($parent && $parent->name == 'OPNsense\Base\BaseModel') {
|
||||
$mdl = $mdl_class_info->newInstance();
|
||||
$version_pre = $mdl->getVersion();
|
||||
$mdl->runMigrations();
|
||||
$mig_performed = $mdl->runMigrations();
|
||||
$version_post = $mdl->getVersion();
|
||||
if ($version_pre != $version_post) {
|
||||
$version_pre = !empty($version_pre) ? $version_pre : ' <unversioned> ';
|
||||
echo "Migrated " . $mdl_class_info->getName() .
|
||||
" from " . $version_pre .
|
||||
" to " . $version_post . "\n";
|
||||
$executed_migration = true;
|
||||
if ($mig_performed) {
|
||||
$version_pre = !empty($version_pre) ? $version_pre : ' <unversioned> ';
|
||||
echo "Migrated " . $mdl_class_info->getName() .
|
||||
" from " . $version_pre .
|
||||
" to " . $version_post . "\n";
|
||||
$executed_migration = true;
|
||||
} else {
|
||||
echo "*** " . $mdl_class_info->getName() . " Migration failed, check log for details\n";
|
||||
}
|
||||
} elseif (!empty($version_post)) {
|
||||
echo "Keep version " . $mdl_class_info->getName() . " (".$version_post.")\n";
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user