[icinga-checkins] icinga.org: icingaweb2-module-director/master: Sync: simplify methods, do not pass $db

git at icinga.org git at icinga.org
Tue Feb 23 13:04:02 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Feb 23 11:55:16 2016 +0100

Sync: simplify methods, do not pass $db

---

 library/Director/Import/Sync.php |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php
index 8e7f4af..b0e095f 100644
--- a/library/Director/Import/Sync.php
+++ b/library/Director/Import/Sync.php
@@ -202,13 +202,13 @@ class Sync
         return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string);
     }
 
-    protected function perpareImportSources($properties, $db)
+    protected function perpareImportSources($properties)
     {
         $sources = array();
         foreach ($properties as $p) {
             $sourceId = $p->source_id;
             if (! array_key_exists($sourceId, $sources)) {
-                $sources[$sourceId] = ImportSource::load($sourceId, $db);
+                $sources[$sourceId] = ImportSource::load($sourceId, $this->db);
             }
         }
 
@@ -268,7 +268,6 @@ class Sync
     {
         $imported = array();
         $rule = $this->rule;
-        $db = $this->db;
 
         $sourceColumns = $this->prepareSourceColumns($properties);
 
@@ -276,7 +275,7 @@ class Sync
             $sourceId = $source->id;
             $key = $source->key_column;
             $sourceColumns[$sourceId][$key] = $key;
-            $rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
+            $rows = $this->db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
 
             $imported[$sourceId] = array();
             foreach ($rows as $row) {
@@ -348,9 +347,8 @@ class Sync
         }
     }
 
-    protected function prepareNewObjects($rule, & $properties, & $sources, & $imported)
+    protected function prepareNewObjects(& $properties, & $sources, & $imported)
     {
-        $db = $rule->getConnection();
         $newObjects = array();
 
         foreach ($sources as $source) {
@@ -385,16 +383,16 @@ class Sync
                 }
                 if (! array_key_exists($key, $newObjects)) {
                     $newObjects[$key] = IcingaObject::createByType(
-                        $rule->object_type,
+                        $this->rule->object_type,
                         array(),
-                        $db
+                        $this->db
                     );
                 }
 
                 $object = $newObjects[$key];
 
                 // Safe default values for object_type and object_name
-                if ($rule->object_type !== 'datalistEntry') {
+                if ($this->rule->object_type !== 'datalistEntry') {
                     if (! array_key_exists('object_type', $newProps)
                         || $newProps['object_type'] === null
                     ) {
@@ -452,7 +450,6 @@ class Sync
 
         // TODO: directly work on existing objects, remember imported keys, then purge
         $newObjects = $this->prepareNewObjects(
-            $rule,
             $properties,
             $sources,
             $imported



More information about the icinga-checkins mailing list