IcingaObject: unify DB boolean value converter

Hint: fixes booleans for "plain unmodified" objects
This commit is contained in:
Thomas Gelf 2021-08-16 06:32:26 +02:00
parent 77fca39ff3
commit 1d5b00a675
1 changed files with 18 additions and 8 deletions

View File

@ -2801,13 +2801,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
// TODO: Do not ship null properties based on flag?
if (!$skipDefaults || $this->differsFromDefaultValue($k, $v)) {
if ($k === 'disabled' || $this->propertyIsBoolean($k)) {
if ($v === 'y') {
$props[$k] = true;
} elseif ($v === 'n') {
$props[$k] = false;
} else {
$props[$k] = $v;
}
$props[$k] = $this->booleanForDbValue($v);
} else {
$props[$k] = $v;
}
@ -2918,6 +2912,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return (object) $props;
}
protected function booleanForDbValue($value)
{
if ($value === 'y') {
return true;
}
if ($value === 'n') {
return false;
}
return $value; // let this fail elsewhere, if not null
}
public function listImportNames()
{
if ($this->gotImports()) {
@ -3052,9 +3058,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
}
if ($this->differsFromDefaultValue($k, $v)) {
if ($k === 'disabled' || $this->propertyIsBoolean($k)) {
$props[$k] = $this->booleanForDbValue($v);
} else {
$props[$k] = $v;
}
}
}
if ($this->supportsCustomVars()) {
$props['vars'] = (object) [];