From ce9a8e1b09d14d47077a0c9db3b6047fb1e63ba0 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 4 Sep 2018 14:31:49 +0200 Subject: [PATCH] IcingaObject: Allow imports to be accessed during onStore() --- library/Director/Objects/IcingaObject.php | 3 ++- library/Director/Resolver/TemplateTree.php | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 580850fd..9129c5b0 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -916,7 +916,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer { $this->assertImportsSupport(); if ($this->imports === null) { - if ($this->hasBeenLoadedFromDb()) { + // can not use hasBeenLoadedFromDb() when in onStore() + if ($this->getProperty('id') !== null) { $this->imports = IcingaObjectImports::loadForStoredObject($this); } else { $this->imports = new IcingaObjectImports($this); diff --git a/library/Director/Resolver/TemplateTree.php b/library/Director/Resolver/TemplateTree.php index c8af6089..951da128 100644 --- a/library/Director/Resolver/TemplateTree.php +++ b/library/Director/Resolver/TemplateTree.php @@ -121,7 +121,9 @@ class TemplateTree public function getParentsFor(IcingaObject $object) { - if ($object->hasBeenLoadedFromDb()) { + // can not use hasBeenLoadedFromDb() when in onStore() + $id = $object->getProperty('id'); + if ($id !== null) { return $this->getParentsById($object->getProperty('id')); } else { throw new RuntimeException( @@ -223,8 +225,10 @@ class TemplateTree public function getChildrenFor(IcingaObject $object) { - if ($object->hasBeenLoadedFromDb()) { - return $this->getChildrenById($object->getProperty('id')); + // can not use hasBeenLoadedFromDb() when in onStore() + $id = $object->getProperty('id'); + if ($id !== null) { + return $this->getChildrenById($id); } else { throw new RuntimeException( 'Loading children for unstored objects has not been implemented yet' @@ -246,8 +250,10 @@ class TemplateTree public function getDescendantsFor(IcingaObject $object) { - if ($object->hasBeenLoadedFromDb()) { - return $this->getDescendantsById($object->getProperty('id')); + // can not use hasBeenLoadedFromDb() when in onStore() + $id = $object->getProperty('id'); + if ($id !== null) { + return $this->getDescendantsById($id); } else { throw new RuntimeException( 'Loading descendants for unstored objects has not been implemented yet'