[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: ImportSource: provide applyModifiers helper method

git at icinga.org git at icinga.org
Fri Jul 22 13:55:47 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed Jul 20 14:25:18 2016 +0200

ImportSource: provide applyModifiers helper method

---

 application/tables/ImportsourceHookTable.php |    7 +------
 library/Director/Import/Import.php           |    7 +------
 library/Director/Objects/ImportSource.php    |   13 +++++++++++++
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/application/tables/ImportsourceHookTable.php b/application/tables/ImportsourceHookTable.php
index 1f142c0..1de1927 100644
--- a/application/tables/ImportsourceHookTable.php
+++ b/application/tables/ImportsourceHookTable.php
@@ -68,12 +68,7 @@ class ImportsourceHookTable extends QuickTable
             }
 
             $this->dataCache = $query->fetchAll();
-
-            if ($this->source->hasRowModifiers()) {
-                foreach ($this->dataCache as & $row) {
-                    $this->source->applyModifiersToRow($row);
-                }
-            }
+            $this->source->applyModifiers($this->dataCache);
         }
 
         return $this->dataCache;
diff --git a/library/Director/Import/Import.php b/library/Director/Import/Import.php
index c90d701..ddef225 100644
--- a/library/Director/Import/Import.php
+++ b/library/Director/Import/Import.php
@@ -166,12 +166,7 @@ class Import
             )->fetchData();
         }
 
-        if ($this->source->hasRowModifiers()) {
-            foreach ($this->data as & $row) {
-                $this->source->applyModifiersToRow($row);
-            }
-        }
-
+        $this->source->applyModifiers($this->data);
         return $this->data;
     }
 
diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php
index fc2dd30..226500a 100644
--- a/library/Director/Objects/ImportSource.php
+++ b/library/Director/Objects/ImportSource.php
@@ -77,6 +77,19 @@ class ImportSource extends DbObjectWithSettings
         return null;
     }
 
+    public function applyModifiers(& $data)
+    {
+        $modifiers = $this->getRowModifiers();
+
+        if (! empty($modifiers)) {
+            foreach ($data as &$row) {
+                $this->applyModifiersToRow($row);
+            }
+        }
+
+        return $this;
+    }
+
     public function applyModifiersToRow(& $row)
     {
         $modifiers = $this->getRowModifiers();



More information about the icinga-checkins mailing list