Commit 1492ddfd authored by Ad Schellevis's avatar Ad Schellevis

(mvc) more work on migrations, fix autoloader, serialize to config when all...

(mvc) more work on migrations, fix autoloader, serialize to config when all steps for this model are finished
parent f55a12b4
...@@ -521,6 +521,7 @@ abstract class BaseModel ...@@ -521,6 +521,7 @@ abstract class BaseModel
public function runMigrations() public function runMigrations()
{ {
if (version_compare($this->internal_current_model_version, $this->internal_model_version, '<')) { 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)); $logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
$class_info = new \ReflectionClass($this); $class_info = new \ReflectionClass($this);
// fetch version migrations // fetch version migrations
...@@ -536,12 +537,14 @@ abstract class BaseModel ...@@ -536,12 +537,14 @@ abstract class BaseModel
// execute upgrade action // execute upgrade action
$tmp = explode('.', basename($filename))[0]; $tmp = explode('.', basename($filename))[0];
$mig_classname = "\\".$class_info->getNamespaceName()."\\Migrations\\".$tmp; $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); $mig_class = new \ReflectionClass($mig_classname);
if ($mig_class->getParentClass()->name == 'OPNsense\Base\BaseModelMigration') { if ($mig_class->getParentClass()->name == 'OPNsense\Base\BaseModelMigration') {
$migobj = $mig_class->newInstance(); $migobj = $mig_class->newInstance();
try { try {
$migobj->run($this); $migobj->run($this);
$this->serializeToConfig(); $upgradePerfomed = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$logger->error("failed migrating from version " . $logger->error("failed migrating from version " .
$this->internal_current_model_version . $this->internal_current_model_version .
...@@ -553,6 +556,11 @@ abstract class BaseModel ...@@ -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();
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment