[icinga-checkins] icinga.org: icingaweb2-module-director/master: Sync: separate datalist cleanup logic

git at icinga.org git at icinga.org
Fri Feb 19 13:02:41 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: c1f3e1c0412c705cf35683679f77e786757181a7
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=c1f3e1c0412c705cf35683679f77e786757181a7

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Feb 19 12:42:02 2016 +0100

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 08063ea..33b09f2 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';
 



More information about the icinga-checkins mailing list