IcingaObject: Allow imports to be accessed during onStore()

This commit is contained in:
Markus Frosch 2018-09-04 14:31:49 +02:00 committed by Thomas Gelf
parent 039a6c8660
commit ce9a8e1b09
2 changed files with 13 additions and 6 deletions

View File

@ -916,7 +916,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
{ {
$this->assertImportsSupport(); $this->assertImportsSupport();
if ($this->imports === null) { if ($this->imports === null) {
if ($this->hasBeenLoadedFromDb()) { // can not use hasBeenLoadedFromDb() when in onStore()
if ($this->getProperty('id') !== null) {
$this->imports = IcingaObjectImports::loadForStoredObject($this); $this->imports = IcingaObjectImports::loadForStoredObject($this);
} else { } else {
$this->imports = new IcingaObjectImports($this); $this->imports = new IcingaObjectImports($this);

View File

@ -121,7 +121,9 @@ class TemplateTree
public function getParentsFor(IcingaObject $object) 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')); return $this->getParentsById($object->getProperty('id'));
} else { } else {
throw new RuntimeException( throw new RuntimeException(
@ -223,8 +225,10 @@ class TemplateTree
public function getChildrenFor(IcingaObject $object) public function getChildrenFor(IcingaObject $object)
{ {
if ($object->hasBeenLoadedFromDb()) { // can not use hasBeenLoadedFromDb() when in onStore()
return $this->getChildrenById($object->getProperty('id')); $id = $object->getProperty('id');
if ($id !== null) {
return $this->getChildrenById($id);
} else { } else {
throw new RuntimeException( throw new RuntimeException(
'Loading children for unstored objects has not been implemented yet' 'Loading children for unstored objects has not been implemented yet'
@ -246,8 +250,10 @@ class TemplateTree
public function getDescendantsFor(IcingaObject $object) public function getDescendantsFor(IcingaObject $object)
{ {
if ($object->hasBeenLoadedFromDb()) { // can not use hasBeenLoadedFromDb() when in onStore()
return $this->getDescendantsById($object->getProperty('id')); $id = $object->getProperty('id');
if ($id !== null) {
return $this->getDescendantsById($id);
} else { } else {
throw new RuntimeException( throw new RuntimeException(
'Loading descendants for unstored objects has not been implemented yet' 'Loading descendants for unstored objects has not been implemented yet'