mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
IcingaObject: allow to replace with plain object
This commit is contained in:
parent
f447457c40
commit
6f0c7aa2a3
@ -2738,19 +2738,26 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
*/
|
*/
|
||||||
public function replaceWith(IcingaObject $object, $preserve = null)
|
public function replaceWith(IcingaObject $object, $preserve = null)
|
||||||
{
|
{
|
||||||
if ($preserve === null) {
|
return $this->replaceWithProperties($object->toPlainObject(), $preserve);
|
||||||
$this->setProperties((array) $object->toPlainObject());
|
}
|
||||||
} else {
|
|
||||||
$plain = (array) $object->toPlainObject();
|
|
||||||
foreach ($preserve as $k) {
|
|
||||||
$v = $this->$k;
|
|
||||||
if ($v !== null) {
|
|
||||||
$plain[$k] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setProperties($plain);
|
/**
|
||||||
|
* @param array|object $properties
|
||||||
|
* @param array $preserve
|
||||||
|
* @return $this
|
||||||
|
* @throws NotFoundError
|
||||||
|
*/
|
||||||
|
public function replaceWithProperties($properties, $preserve = [])
|
||||||
|
{
|
||||||
|
$properties = (array) $properties;
|
||||||
|
foreach ($preserve as $k) {
|
||||||
|
$v = $this->get($k);
|
||||||
|
if ($v !== null) {
|
||||||
|
$properties[$k] = $v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$this->setProperties($properties);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user