From 61f3ffff7e24323f4fd22de64e0537ad7a00c44f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 14 Oct 2016 09:12:05 +0000 Subject: [PATCH] TemplateResolver: deal with unstored modified... ...imports property fixes #12922 --- .../Objects/IcingaTemplateResolver.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/library/Director/Objects/IcingaTemplateResolver.php b/library/Director/Objects/IcingaTemplateResolver.php index 3ac8c2f7..a075baf1 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()