diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 00e1678f..df6f2462 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -51,7 +51,7 @@ class Sync /** * Objects to work with * - * @var array + * @var IcingaObject[] */ protected $objects; @@ -72,6 +72,8 @@ class Sync protected $syncProperties; + protected $replaceVars = false; + /** * @var SyncRun */ @@ -181,6 +183,10 @@ class Sync { $this->syncProperties = $this->rule->fetchSyncProperties(); foreach ($this->syncProperties as $key => $prop) { + if ($prop->destination_field === 'vars' && $prop->merge_policy === 'override') { + $this->replaceVars = true; + } + if (! strlen($prop->filter_expression)) { continue; } @@ -247,8 +253,8 @@ class Sync /** * Fetch latest imported data rows from all involved import sources - * - * @return self + * @return Sync + * @throws IcingaException */ protected function fetchImportedData() { @@ -395,7 +401,7 @@ class Sync // TODO: should be obsoleted by a better "loadFiltered" method if ($this->rule->object_type === 'datalistEntry') { - $this->removeForeignListEntries($this->objects); + $this->removeForeignListEntries(); } return $this; @@ -500,13 +506,16 @@ class Sync return $this; } + /** + * @param IcingaObject $object + * @return $this + */ protected function setResolver($object) { - if (! ($object instanceof IcingaObject)) { + if (! ($object instanceof IcingaHost || $object instanceof IcingaHostGroup)) { return $this; } if ($resolver = $this->gethostGroupMembershipResolver()) { - /** @var IcingaHost|IcingaHostGroup $object */ $object->setHostGroupMembershipResolver($resolver); } @@ -522,6 +531,9 @@ class Sync return $this; } + /** + * @return bool|HostGroupMembershipResolver + */ protected function gethostGroupMembershipResolver() { if ($this->hostGroupMembershipResolver === null) { @@ -577,7 +589,7 @@ class Sync case 'merge': // TODO: re-evaluate merge settings. vars.x instead of // just "vars" might suffice. - $this->objects[$key]->merge($object); + $this->objects[$key]->merge($object, $this->replaceVars); break; default: @@ -620,8 +632,9 @@ class Sync /** * Runs a SyncRule and applies all resulting changes - * * @return int + * @throws Exception + * @throws IcingaException */ public function apply() { diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 4595a465..359af69a 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -2412,7 +2412,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } // TODO: with rules? What if I want to override vars? Drop in favour of vars.x? - public function merge(IcingaObject $object) + public function merge(IcingaObject $object, $replaceVars = false) { $object = clone($object); @@ -2425,9 +2425,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer if ($object->supportsCustomVars()) { $myVars = $this->vars(); - /** @var CustomVariables $vars */ - foreach ($vars as $key => $var) { - $myVars->set($key, $var); + if ($replaceVars) { + $this->set('vars', $vars); + } else { + /** @var CustomVariables $vars */ + foreach ($vars as $key => $var) { + $myVars->set($key, $var); + } } }