diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 805d7604..7fe180c7 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -19,7 +19,6 @@ use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; use Icinga\Module\Director\Repository\IcingaTemplateRepository; -use Icinga\Module\Director\Resolver\TemplateTree; abstract class IcingaObject extends DbObject implements IcingaConfigRenderer { @@ -871,6 +870,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->listImportNames(); } + /** + * @deprecated This should no longer be in use + * @return IcingaTemplateResolver + */ public function templateResolver() { if ($this->templateResolver === null) { @@ -2437,7 +2440,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer if ($object->supportsCustomVars()) { $vars = $object->getVars(); - $object->vars = array(); + $object->set('vars', []); } $this->setProperties((array) $object->toPlainObject(null, true)); diff --git a/library/Director/Objects/IcingaObjectImports.php b/library/Director/Objects/IcingaObjectImports.php index 388fa2c0..1e575948 100644 --- a/library/Director/Objects/IcingaObjectImports.php +++ b/library/Director/Objects/IcingaObjectImports.php @@ -274,7 +274,8 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer { // $resolver = $this->object->templateResolver(); // $this->objects = $resolver->fetchParents(); - $this->objects = IcingaTemplateRepository::instanceByObject($this->object)->getTemplatesFor($this->object); + $this->objects = IcingaTemplateRepository::instanceByObject($this->object) + ->getTemplatesIndexedByNameFor($this->object); if (empty($this->objects)) { $this->imports = array(); } else { diff --git a/library/Director/Repository/IcingaTemplateRepository.php b/library/Director/Repository/IcingaTemplateRepository.php index 3d2ef83e..9af713fd 100644 --- a/library/Director/Repository/IcingaTemplateRepository.php +++ b/library/Director/Repository/IcingaTemplateRepository.php @@ -50,6 +50,20 @@ class IcingaTemplateRepository return $templates; } + /** + * @param IcingaObject $object + * @return IcingaObject[] + */ + public function getTemplatesIndexedByNameFor(IcingaObject $object) + { + $templates = []; + foreach ($this->getTemplatesFor($object) as $template) { + $templates[$template->getObjectName()] = $template; + } + + return $templates; + } + public function persistImportNames() { }