From 3200c0ba8564e034abf61ccba2f6775f17251542 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 7 Mar 2024 12:43:59 +0100 Subject: [PATCH] mvc: "make validate" was not validating the full model... ... which was the intention of this helper. Now, we see a lot of other things that need fixing, but there is an implication for migrations ("make migrate") where the copy of that function came from... Apparenlty migration only validates the model changes done during migration, which is fine, but if we are restricting validation further during a migration and forget to change these fields they are not marked for validation and thus "validate" "correctly" leaving them in a broken state in the config. This can be cross-checked by the GUI attempting to save these faulty values which is then no longer possible. Needs more discussion. --- src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php | 6 +++--- src/opnsense/mvc/script/run_validations.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php index e62eb1900..8c36dd178 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php @@ -507,10 +507,10 @@ abstract class BaseModel * @param string $targetref target reference, for example section. used as prefix if no source given * @return array list of validation errors, indexed by field reference */ - public function validate($sourceref = null, $targetref = "") + public function validate($sourceref = null, $targetref = '', $validateFullModel = false) { - $result = array(); - $valMsgs = $this->performValidation(); + $result = []; + $valMsgs = $this->performValidation($validateFullModel); foreach ($valMsgs as $msg) { // replace absolute path to attribute for relative one at uuid. if ($sourceref != null) { diff --git a/src/opnsense/mvc/script/run_validations.php b/src/opnsense/mvc/script/run_validations.php index 047f8c382..6ecffd01b 100755 --- a/src/opnsense/mvc/script/run_validations.php +++ b/src/opnsense/mvc/script/run_validations.php @@ -50,7 +50,7 @@ foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($model_dir $name = $mdl_class_info->getName(); $mdl = $mdl_class_info->newInstance(); if (!$mdl->isVolatile()) { - $msgs = $mdl->validate(); + $msgs = $mdl->validate(null, '', true); foreach ($msgs as $key => $msg) { echo sprintf('%s.%s => %s', $name, $key, $msg) . PHP_EOL; }