[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: ImportRowModifier: provide target_property...

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


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed Jul 20 13:41:16 2016 +0200

ImportRowModifier: provide target_property...

...also adjust the related form

refs #11949

---

 application/forms/ImportRowModifierForm.php    |   10 ++++++++++
 library/Director/Hook/PropertyModifierHook.php |   15 ++++++++++++++-
 library/Director/Objects/ImportRowModifier.php |   12 +++++++-----
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/application/forms/ImportRowModifierForm.php b/application/forms/ImportRowModifierForm.php
index 4b640c0..3e280ee 100644
--- a/application/forms/ImportRowModifierForm.php
+++ b/application/forms/ImportRowModifierForm.php
@@ -25,6 +25,16 @@ class ImportRowModifierForm extends DirectorObjectForm
             'required'     => true,
         ));
 
+        $this->addElement('text', 'target_property', array(
+            'label'        => $this->translate('Target property'),
+            'description'  => $this->translate(
+                'You might want to write the modified value to another (new) property.' 
+                . ' This property name can be defined here, the original property would'
+                . ' remain unmodified. Please leave this blank in case you just want to'
+                . ' modify the value of a specific property'
+            ),
+        ));
+
         $error = false;
         try {
             $mods = $this->enumModifiers();
diff --git a/library/Director/Hook/PropertyModifierHook.php b/library/Director/Hook/PropertyModifierHook.php
index c5d2751..8ad195c 100644
--- a/library/Director/Hook/PropertyModifierHook.php
+++ b/library/Director/Hook/PropertyModifierHook.php
@@ -9,6 +9,8 @@ abstract class PropertyModifierHook
 {
     protected $settings = array();
 
+    private $targetProperty;
+
     private $db;
 
     public function getName()
@@ -26,9 +28,20 @@ abstract class PropertyModifierHook
         return $class;
     }
 
+    public function setTargetProperty($property)
+    {
+        $this->targetProperty = $property;
+        return $this;
+    }
+
+    public function hasTargetProperty()
+    {
+        return $this->targetProperty !== null;
+    }
+
     public function getTargetProperty()
     {
-        return null;
+        return $this->targetProperty;
     }
 
     public function setDb(Db $db)
diff --git a/library/Director/Objects/ImportRowModifier.php b/library/Director/Objects/ImportRowModifier.php
index 240074e..5ee94c0 100644
--- a/library/Director/Objects/ImportRowModifier.php
+++ b/library/Director/Objects/ImportRowModifier.php
@@ -13,11 +13,12 @@ class ImportRowModifier extends DbObjectWithSettings
     protected $autoincKeyName = 'id';
 
     protected $defaultProperties = array(
-        'id'             => null,
-        'source_id'      => null,
-        'property_name'  => null,
-        'provider_class' => null,
-        'priority'       => null,
+        'id'              => null,
+        'source_id'       => null,
+        'property_name'   => null,
+        'provider_class'  => null,
+        'target_property' => null,
+        'priority'        => null,
     );
 
     protected $settingsTable = 'import_row_modifier_setting';
@@ -31,6 +32,7 @@ class ImportRowModifier extends DbObjectWithSettings
         if ($this->hookInstance === null) {
             $obj = new $this->provider_class;
             $obj->setSettings($this->getSettings());
+            $obj->setTargetProperty($this->target_property);
             $obj->setDb($this->connection);
             $this->hookInstance = $obj;
         }



More information about the icinga-checkins mailing list