From 14ea1b96e8923ca0a571e73124930f86ecbd63ae Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 25 Mar 2024 21:12:46 +0100 Subject: [PATCH] mvc - change exception handling in runMigrations() to avoid mismatches in attributes being silently ignored. When a migration tries to address an non existing attribute, a InvalidArgumentException is thrown, but only partially noted in the log. It's likely safer to abort the migration if steps fail and send the error to the log for further inspection. --- src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php index 8c36dd178..4b47aa652 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php @@ -721,7 +721,7 @@ abstract class BaseModel $class_info = new ReflectionClass($this); // fetch version migrations - $versions = array(); + $versions = []; // set default migration for current model version $versions[$this->internal_model_version] = __DIR__ . "/BaseModelMigration.php"; $migprefix = $this->internal_model_migration_prefix; @@ -757,7 +757,10 @@ abstract class BaseModel } catch (Exception $e) { $logger->error("failed migrating from version " . $this->getVersion() . " to " . $mig_version . " in " . - $class_info->getName() . " [skipping step]"); + $class_info->getName() . " ( " . $e . " )"); + /* fail migration when exceptions are thrown */ + $this->internal_current_model_version = $mig_version; + return false; } $this->internal_current_model_version = $mig_version; }