From c1f3e1c0412c705cf35683679f77e786757181a7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 19 Feb 2016 12:42:02 +0100 Subject: [PATCH] Sync: separate datalist cleanup logic --- library/Director/Import/Sync.php | 54 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 08063ea5..33b09f22 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -257,6 +257,34 @@ class Sync return $imported; } + // TODO: This is rubbish, we need to filter at fetch time + protected function removeForeignListEntries(& $objects, & $properties) + { + $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 $k => $o) { + if ($o->list_id !== $listId) { + $no[] = $k; + } + } + + foreach ($no as $k) { + unset($objects[$k]); + } + } + /** * Evaluates a SyncRule and returns a list of modified objects * @@ -273,33 +301,11 @@ class Sync $sources = $this->perpareImportSources($properties, $db); $imported = $this->fetchImportedData($sources, $properties, $rule, $db); - // TODO: Filter auf object, nicht template + // TODO: Make object_type and object_name mandatory? $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 $k => $o) { - if ($o->list_id !== $listId) { - $no[] = $k; - } - } - - foreach ($no as $k) { - unset($objects[$k]); - } + $this->removeForeignListEntries($objects, $properties); } $objectKey = $rule->object_type === 'datalistEntry' ? 'entry_name' : 'object_name';