mvc: do not migrate unversioned empty model data

This commit is contained in:
Franco Fichtner 2021-01-14 16:12:53 +01:00
parent f23c57f4b9
commit 6ed3e4fe8d
2 changed files with 9 additions and 5 deletions

View File

@ -336,10 +336,11 @@ abstract class BaseModel
$this->parseXml($model_xml->items, $config_array, $this->internalData);
// root may contain a version, store if found
if (empty($config_array)) {
// new node, reset
$this->internal_current_model_version = "0.0.0";
$this->internal_current_model_version = null;
} elseif (!empty($config_array->attributes()['version'])) {
$this->internal_current_model_version = (string)$config_array->attributes()['version'];
} else {
$this->internal_current_model_version = "0.0.0";
}
// trigger post loading event
@ -629,7 +630,10 @@ abstract class BaseModel
*/
public function runMigrations()
{
if (version_compare($this->internal_current_model_version, $this->internal_model_version, '<')) {
if (
$this->internal_current_model_version !== null &&
version_compare($this->internal_current_model_version, $this->internal_model_version, '<')
) {
$upgradePerfomed = false;
$migObjects = array();
$logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));

View File

@ -56,7 +56,7 @@ foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($model_dir
$version_post = $mdl->getVersion();
if ($version_pre != $version_post) {
if ($mig_performed) {
$version_pre = !empty($version_pre) ? $version_pre : ' <unversioned> ';
$version_pre = !empty($version_pre) ? $version_pre : '<unversioned>';
echo "Migrated " . $mdl_class_info->getName() .
" from " . $version_pre .
" to " . $version_post . "\n";
@ -67,7 +67,7 @@ foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($model_dir
} elseif (!empty($version_post)) {
echo "Keep version " . $mdl_class_info->getName() . " (" . $version_post . ")\n";
} else {
echo "Unversioned " . $mdl_class_info->getName() . "\n";
echo "Keep unversioned " . $mdl_class_info->getName() . "\n";
}
}
} catch (\ReflectionException $e) {