[icinga-checkins] icinga.org: icingaweb2-module-director/feature/nested-apply-rules-12033: FieldLoader, TemplateResolver: more cleanup

git at icinga.org git at icinga.org
Fri Oct 21 10:08:05 CEST 2016


Module: icingaweb2-module-director
Branch: feature/nested-apply-rules-12033
Commit: 041fd52174b494aed4161c048042dd930359b8ea
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=041fd52174b494aed4161c048042dd930359b8ea

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

FieldLoader, TemplateResolver: more cleanup

A few fixes related to modified imports for unstored objects

refs #12922

---

 .../Director/Objects/IcingaTemplateResolver.php    |   25 ++++++++++++++------
 library/Director/Web/Form/DirectorObjectForm.php   |    2 +-
 .../Director/Web/Form/IcingaObjectFieldLoader.php  |   13 +++++-----
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/library/Director/Objects/IcingaTemplateResolver.php b/library/Director/Objects/IcingaTemplateResolver.php
index 1890e0d..20eed6d 100644
--- a/library/Director/Objects/IcingaTemplateResolver.php
+++ b/library/Director/Objects/IcingaTemplateResolver.php
@@ -117,8 +117,17 @@ class IcingaTemplateResolver
         $this->requireTemplates();
 
         if ($name === null) {
-            $name = $this->object->object_name;
-            if ($this->object->imports()->hasBeenModified()) {
+
+            $object = $this->object;
+
+            if ($object->hasBeenLoadedFromDb()) {
+
+                if ($object->gotImports() && $object->imports()->hasBeenModified()) {
+                    return $this->listUnstoredParentNames();
+                }
+
+                $name = $object->object_name;
+            } else {
                 return $this->listUnstoredParentNames();
             }
         }
@@ -140,7 +149,7 @@ class IcingaTemplateResolver
     public function listResolvedParentIds()
     {
         $this->requireTemplates();
-        return $this->resolveParentIds($this->object->id);
+        return $this->resolveParentIds();
     }
 
     public function listResolvedParentNames()
@@ -166,9 +175,9 @@ class IcingaTemplateResolver
     protected function resolveParentNames($name, &$list = array())
     {
         foreach ($this->listParentNames($name) as $parent) {
-            $this->assertNotInList($parent, $list, $id);
+            $this->assertNotInList($parent, $list, $name);
             $list[$parent] = true;
-            $this->resolveParentIds($parent, $list);
+            $this->resolveParentNames($parent, $list);
             unset($list[$parent]);
             $list[$parent] = true;
         }
@@ -176,10 +185,12 @@ class IcingaTemplateResolver
         return array_keys($list);
     }
 
-    protected function resolveParentIds($id, &$list = array())
+    protected function resolveParentIds($id = null, &$list = array())
     {
         foreach ($this->listParentIds($id) as $parent) {
-            $this->assertNotInList($parent, $list, $id);
+            if ($id !== null) {
+                $this->assertNotInList($parent, $list, $id);
+            }
             $list[$parent] = true;
             $this->resolveParentIds($parent, $list);
             unset($list[$parent]);
diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php
index 485390b..9ab41d9 100644
--- a/library/Director/Web/Form/DirectorObjectForm.php
+++ b/library/Director/Web/Form/DirectorObjectForm.php
@@ -273,7 +273,7 @@ abstract class DirectorObjectForm extends QuickForm
 
     protected function handleCustomVars($object, & $values)
     {
-        IcingaObjectFieldLoader::addFieldsToForm($this, $values);
+        IcingaObjectFieldLoader::addFieldsToForm($this, $object, $values);
     }
 
     protected function isNew()
diff --git a/library/Director/Web/Form/IcingaObjectFieldLoader.php b/library/Director/Web/Form/IcingaObjectFieldLoader.php
index e8feec3..a6dad1c 100644
--- a/library/Director/Web/Form/IcingaObjectFieldLoader.php
+++ b/library/Director/Web/Form/IcingaObjectFieldLoader.php
@@ -3,6 +3,7 @@
 namespace Icinga\Module\Director\Web\Form;
 
 use Icinga\Module\Director\Exception\NestingError;
+use Icinga\Module\Director\Objects\IcingaObject;
 use Icinga\Module\Director\Objects\IcingaServiceSet;
 use Icinga\Module\Director\Objects\DirectorDatafield;
 use stdClass;
@@ -13,19 +14,19 @@ class IcingaObjectFieldLoader
 
     protected $object;
 
-    protected function __construct(DirectorObjectForm $form)
+    protected function __construct(DirectorObjectForm $form, IcingaObject $object)
     {
-        $this->form = $form;        
-        $this->object = $form->getObject();
+        $this->form = $form;
+        $this->object = $object;
     }
 
-    public static function addFieldsToForm(DirectorObjectForm $form, & $values)
+    public static function addFieldsToForm(DirectorObjectForm $form, IcingaObject $object, & $values)
     {
-        if (! $form->getObject()->supportsCustomVars()) {
+        if (! $object->supportsCustomVars()) {
             return $form;
         }
 
-        $loader = new static($form);
+        $loader = new static($form, $object);
         $loader->addFields();
         if ($values !== null) {
             $loader->setValues($loader->stripKeyPrefix($values, 'var_'));



More information about the icinga-checkins mailing list