mvc: fix PHP warnings and dance around null/0.0.0 ambiguity

If we have a model and no data we assume and write 0.0.0, but if we
have a legacy data we want to have null to designate that we do
actually migrate although from the top point of view 0.0.0 are the
same.
This commit is contained in:
Franco Fichtner 2023-03-09 10:56:58 +01:00
parent 84f0bcdbdb
commit 74fe31682f
2 changed files with 5 additions and 8 deletions

View File

@ -644,7 +644,7 @@ abstract class BaseModel
{
if ($this->internal_mountpoint == ':memory:') {
return false;
} elseif (version_compare($this->internal_current_model_version, $this->internal_model_version, '<')) {
} elseif (version_compare($this->internal_current_model_version ?? '0.0.0', $this->internal_model_version, '<')) {
$upgradePerformed = false;
$migObjects = array();
$logger = new Logger(
@ -667,7 +667,7 @@ abstract class BaseModel
uksort($versions, "version_compare");
foreach ($versions as $mig_version => $filename) {
if (
version_compare($this->internal_current_model_version, $mig_version, '<') &&
version_compare($this->internal_current_model_version ?? '0,0.0', $mig_version, '<') &&
version_compare($this->internal_model_version, $mig_version, '>=')
) {
// execute upgrade action
@ -690,10 +690,8 @@ abstract class BaseModel
$upgradePerformed = true;
} catch (Exception $e) {
$logger->error("failed migrating from version " .
$this->internal_current_model_version .
" to " . $mig_version . " in " .
$class_info->getName() .
" [skipping step]");
$this->getVersion() . " to " . $mig_version . " in " .
$class_info->getName() . " [skipping step]");
}
$this->internal_current_model_version = $mig_version;
}
@ -724,6 +722,6 @@ abstract class BaseModel
*/
public function getVersion()
{
return $this->internal_current_model_version;
return $this->internal_current_model_version ?? '<unversioned>';
}
}

View File

@ -55,7 +55,6 @@ 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>';
echo "Migrated " . $mdl_class_info->getName() .
" from " . $version_pre .
" to " . $version_post . "\n";