Gateways: Single: Migrate to MVC - part 2: Do not persist dpinger defaults

This commit is contained in:
Stephan de Wit 2023-11-02 11:28:19 +01:00
parent a55b4c8b22
commit 2fb2ae85fd
3 changed files with 15 additions and 10 deletions

View File

@ -121,6 +121,13 @@ function dpinger_instances($extended = false)
}
}
foreach (\OPNsense\Routing\Gateways::getDpingerDefaults() as $key => $value) {
/* make sure callers can reliably query the dpinger settings */
if (empty($gateway[$key])) {
$gateway[$key] = $value;
}
}
$instances[$name] = $gateway;
}

View File

@ -72,9 +72,13 @@ class Gateways extends BaseModel
$tagName = $node->getInternalXMLTagName();
if (array_key_exists($tagName, $defaults)) {
if (empty((string)$node)) {
// Since dpinger values are not required in the model,
// we set them to the defaults here if they're empty.
/*
* Since dpinger values are not required in the model,
* we set them to the defaults here if they're empty, but keep them virtual so
* they're not persisted. The validations below might depend on the values being set.
*/
$node->setValue($defaults[$tagName]);
$node->setInternalIsVirtual(true);
}
}
}
@ -272,7 +276,8 @@ class Gateways extends BaseModel
foreach ($this->getDpingerDefaults() as $key => $value) {
if (empty($record[$key])) {
$record[$key] = $value;
// make sure node exists without value set
$record[$key] = '';
}
}
$record['uuid'] = '';

View File

@ -74,13 +74,6 @@ class M1_0_0 extends BaseModelMigration
$node->$key = (string)$value;
}
// apply dpinger defaults if old model didn't have them set
foreach (Gateways::getDpingerDefaults() as $key => $value) {
if (empty((string)$node->$key)) {
$node->$key = $value;
}
}
// increase time period if old model had it set too low
$min_time_period = 2 * (intval((string)$node->interval) + intval((string)$node->loss_interval));
if ((string)$node->time_period < $min_time_period) {