Sync: delegate new "replace" to the object

This commit is contained in:
Thomas Gelf 2015-12-15 19:09:22 +01:00
parent 738a690c43
commit f7d9867b97
1 changed files with 7 additions and 5 deletions

View File

@ -299,24 +299,25 @@ class Sync
} }
} }
} }
if (array_key_exists($key, $objects)) { if (array_key_exists($key, $objects)) {
switch ($rule->update_policy) { switch ($rule->update_policy) {
case 'override': case 'override':
// TODO: Only override if it doesn't equal $object = IcingaObject::createByType(
$objects[$key] = IcingaObject::createByType(
$rule->object_type, $rule->object_type,
$newProps, $newProps,
$db $db
); );
foreach ($newVars as $prop => $var) { foreach ($newVars as $prop => $var) {
$objects[$key]->vars()->$prop = $var; $object->vars()->$prop = $var;
} }
if (! empty($imports)) { if (! empty($imports)) {
$objects[$key]->imports()->set($imports); $object->imports()->set($imports);
} }
$objects[$key]->replaceWith($object);
break; break;
case 'merge': case 'merge':
@ -413,6 +414,7 @@ class Sync
$db = $rule->getConnection(); $db = $rule->getConnection();
// TODO: Evaluate whether fetching data should happen within the same transaction // TODO: Evaluate whether fetching data should happen within the same transaction
$objects = $this->prepareSyncForRule($rule); $objects = $this->prepareSyncForRule($rule);
$dba = $db->getDbAdapter(); $dba = $db->getDbAdapter();
$dba->beginTransaction(); $dba->beginTransaction();
foreach ($objects as $object) { foreach ($objects as $object) {