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

View File

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