[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject: load and store related sets

git at icinga.org git at icinga.org
Mon Feb 29 20:39:05 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Feb 29 18:57:19 2016 +0100

IcingaObject: load and store related sets

---

 library/Director/Objects/IcingaObject.php |   34 +++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 6794ee2..a9fcf50 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -47,6 +47,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         // property => ExtensibleSetClass
     );
 
+    protected $loadedRelatedSets = array();
+
     /**
      * Array of interval property names
      *
@@ -96,8 +98,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
 
     protected function getRelatedSet($property)
     {
-        $class = $this->getRelatedSetClass($property);
-        return $class::forIcingaObject($this, $property);
+        if (! array_key_exists($property, $this->loadedRelatedSets)) {
+            $class = $this->getRelatedSetClass($property);
+            $this->loadedRelatedSets[$property]
+                 = $class::forIcingaObject($this, $property);
+        }
+
+        return $this->loadedRelatedSets[$property];
     }
 
     public function hasRelation($property)
@@ -179,6 +186,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             return true;
         }
 
+        foreach ($this->loadedRelatedSets as $set) {
+            if ($set->hasBeenModified()) {
+                return true;
+            }
+        }
+
         return parent::hasBeenModified();
     }
 
@@ -253,6 +266,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             // TODO: what shall we do if it is a template? Fail?
         }
 
+        if ($this->propertyIsRelatedSet($key)) {
+            $this->getRelatedSet($key)->set($value);
+            return $this;
+        }
+
         if ($this->propertyIsInterval($key)) {
             return parent::set($key, c::parseInterval($value));
         }
@@ -764,6 +782,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             ->storeGroups()
             ->storeImports()
             ->storeRanges()
+            ->storeRelatedSets()
             ->storeArguments();
     }
 
@@ -815,6 +834,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return $this;
     }
 
+    protected function storeRelatedSets()
+    {
+        foreach ($this->loadedRelatedSets as $set) {
+            if ($set->hasBeenModified()) {
+                $set->store();
+            }
+        }
+
+        return $this;
+    }
+
     protected function storeImports()
     {
         if ($this->supportsImports()) {



More information about the icinga-checkins mailing list