(mvc) more work on migrations, fix autoloader, serialize to config when all steps for this model are finished

This commit is contained in:
Ad Schellevis 2016-08-12 14:35:17 +02:00
parent f55a12b466
commit 1492ddfd39

View File

@ -521,6 +521,7 @@ abstract class BaseModel
public function runMigrations()
{
if (version_compare($this->internal_current_model_version, $this->internal_model_version, '<')) {
$upgradePerfomed = false;
$logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
$class_info = new \ReflectionClass($this);
// fetch version migrations
@ -536,12 +537,14 @@ abstract class BaseModel
// execute upgrade action
$tmp = explode('.', basename($filename))[0];
$mig_classname = "\\".$class_info->getNamespaceName()."\\Migrations\\".$tmp;
// Phalcon's autoloader uses _ as a directory locator, we need to import these files ourselves
require_once $filename;
$mig_class = new \ReflectionClass($mig_classname);
if ($mig_class->getParentClass()->name == 'OPNsense\Base\BaseModelMigration') {
$migobj = $mig_class->newInstance();
try {
$migobj->run($this);
$this->serializeToConfig();
$upgradePerfomed = true;
} catch (\Exception $e) {
$logger->error("failed migrating from version " .
$this->internal_current_model_version .
@ -553,6 +556,11 @@ abstract class BaseModel
}
}
}
// serialize to config after last migration step, keep the config data static as long as not all
// migrations have completed.
if ($upgradePerfomed) {
$this->serializeToConfig();
}
}
}