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();
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);

View File

@ -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'