[icinga-checkins] icinga.org: icingaweb2-module-director/master: TemplateResolver: deal with unstored modified...

git at icinga.org git at icinga.org
Fri Oct 14 11:18:50 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Oct 14 09:12:05 2016 +0000

TemplateResolver: deal with unstored modified...

...imports property

fixes #12922

---

 .../Director/Objects/IcingaTemplateResolver.php    |   37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/library/Director/Objects/IcingaTemplateResolver.php b/library/Director/Objects/IcingaTemplateResolver.php
index 3ac8c2f..a075baf 100644
--- a/library/Director/Objects/IcingaTemplateResolver.php
+++ b/library/Director/Objects/IcingaTemplateResolver.php
@@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Objects;
 use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Exception\NestingError;
 
+// TODO: move the 'type' layer to another class
 class IcingaTemplateResolver
 {
     protected $object;
@@ -23,6 +24,8 @@ class IcingaTemplateResolver
 
     protected static $idToName = array();
 
+    protected static $nameToId = array();
+
     public function __construct(IcingaObject $object)
     {
         $this->setObject($object);
@@ -77,6 +80,9 @@ class IcingaTemplateResolver
 
         if ($id === null) {
             $id = $this->object->id;
+            if (! $id && $this->object->imports()->hasBeenModified()) {
+                return $this->listUnstoredParentIds();
+            }
         }
 
         $type = $this->type;
@@ -88,12 +94,25 @@ class IcingaTemplateResolver
         return array();
     }
 
+    protected function listUnstoredParentIds()
+    {
+        return $this->getIdsForNames($this->listUnstoredParentNames());
+    }
+
+    protected function listUnstoredParentNames()
+    {
+        return $this->object->imports()->listImportNames();
+    }
+
     public function listParentNames($name = null)
     {
         $this->requireTemplates();
 
         if ($name === null) {
             $name = $this->object->object_name;
+            if ($this->object->imports()->hasBeenModified()) {
+                return $this->listUnstoredParentNames();
+            }
         }
 
         $type = $this->type;
@@ -189,6 +208,21 @@ class IcingaTemplateResolver
         return self::$idToName[$this->type][$id];
     }
 
+    protected function getIdsForNames($names)
+    {
+        $id = array();
+        foreach ($names as $name) {
+            $ids[] = $this->getIdForName($name);
+        }
+
+        return $ids;
+    }
+
+    protected function getIdForName($name)
+    {
+        return self::$nameToId[$this->type][$name];
+    }
+
     protected function fetchObjectsById($ids)
     {
         $class = $this->object;
@@ -220,9 +254,11 @@ class IcingaTemplateResolver
         $ids = array();
         $names = array();
         $idToName = array();
+        $nameToId = array();
 
         foreach ($templates as $row) {
             $idToName[$row->id] = $row->name;
+            $nameToId[$row->name] = $row->id;
 
             if ($row->parent_id === null) {
                 continue;
@@ -245,6 +281,7 @@ class IcingaTemplateResolver
         self::$nameIdx[$type]   = $names;
         self::$templates[$type] = $templates;
         self::$idToName[$type]  = $idToName;
+        self::$nameToId[$type]  = $nameToId;
     }
 
     protected function fetchTemplates()



More information about the icinga-checkins mailing list