IcingaObject: add merge method, use in Sync

This commit is contained in:
Thomas Gelf 2016-02-25 00:23:27 +01:00
parent f0d02edbe6
commit 1261bd93e1
2 changed files with 16 additions and 1 deletions

View File

@ -600,7 +600,7 @@ class Sync
case 'merge':
// TODO: re-evaluate merge settings. vars.x instead of
// just "vars" might suffice.
$this->objects[$key]->setProperties($object);
$this->objects[$key]->merge($object);
break;
default:

View File

@ -1114,6 +1114,21 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this;
}
// TODO: with rules? What if I want to override vars? Drop in favour of vars.x?
public function merge(IcingaObject $object)
{
$object = clone($object);
$vars = $object->getVars();
$object->vars = array();
$this->setProperties((array) $object->toPlainObject());
$myVars = $this->vars();
foreach ($vars as $key => $var) {
$myVars->set($key, $var);
}
return $this;
}
public function toPlainObject(
$resolved = false,
$skipDefaults = false,