From ad39da9a138c1ac9335ae806b272dcbc8ac1d54d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 9 Feb 2016 19:21:36 +0100 Subject: [PATCH] Sync: fix datalist entry sync --- library/Director/Import/Sync.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index ae44547c..08063ea5 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -277,9 +277,28 @@ class Sync $objects = IcingaObject::loadAllByType($rule->object_type, $db); if ($rule->object_type === 'datalistEntry') { + $listId = null; + foreach ($properties as $prop) { + if ($prop->destination_field === 'list_id') { + $listId = (int) $prop->source_expression; + } + } + + if ($listId === null) { + throw new IcingaException( + 'Cannot sync datalist entry without list_ist' + ); + } + $no = array(); - foreach ($objects as $o) { - // if ($o->list_id !== $source-> + foreach ($objects as $k => $o) { + if ($o->list_id !== $listId) { + $no[] = $k; + } + } + + foreach ($no as $k) { + unset($objects[$k]); } } $objectKey = $rule->object_type === 'datalistEntry' ? 'entry_name' : 'object_name'; @@ -447,7 +466,9 @@ class Sync } continue; } - if ($object->shouldBeRemoved()) { + + // TODO: introduce DirectorObject with shouldBeRemoved + if ($object instanceof IcingaObject && $object->shouldBeRemoved()) { $object->delete($db); continue; }