IcingaObject: fix lezy-loading issues
This commit is contained in:
parent
407a47a6ec
commit
670b932526
|
@ -231,12 +231,21 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
return parent::hasBeenModified();
|
return parent::hasBeenModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function hasUnresolvedRelatedProperty($name)
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->unresolvedRelatedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
|
if ($this->hasUnresolvedRelatedProperty($key . '_id')) {
|
||||||
|
return $this->unresolvedRelatedProperties[$key . '_id'];
|
||||||
|
}
|
||||||
|
|
||||||
if (substr($key, -3) === '_id') {
|
if (substr($key, -3) === '_id') {
|
||||||
$short = substr($key, 0, -3);
|
$short = substr($key, 0, -3);
|
||||||
if ($this->hasRelation($short)) {
|
if ($this->hasRelation($short)) {
|
||||||
if (array_key_exists($key, $this->unresolvedRelatedProperties)) {
|
if ($this->hasUnresolvedRelatedProperty($key)) {
|
||||||
$this->resolveUnresolvedRelatedProperty($key);
|
$this->resolveUnresolvedRelatedProperty($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -868,6 +877,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
->storeArguments();
|
->storeArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function beforeStore()
|
||||||
|
{
|
||||||
|
$this->resolveUnresolvedRelatedProperties();
|
||||||
|
}
|
||||||
|
|
||||||
public function onInsert()
|
public function onInsert()
|
||||||
{
|
{
|
||||||
DirectorActivityLog::logCreation($this, $this->connection);
|
DirectorActivityLog::logCreation($this, $this->connection);
|
||||||
|
@ -968,6 +982,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
|
|
||||||
foreach ($this->properties as $key => $value) {
|
foreach ($this->properties as $key => $value) {
|
||||||
|
|
||||||
|
if (substr($key, -3) === '_id') {
|
||||||
|
$short = substr($key, 0, -3);
|
||||||
|
if ($this->hasUnresolvedRelatedProperty($key)) {
|
||||||
|
$out .= c::renderKeyValue(
|
||||||
|
$short, // NOT
|
||||||
|
c::renderString($this->$short)
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1308,7 +1334,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
$relKey = substr($k, 0, -3);
|
$relKey = substr($k, 0, -3);
|
||||||
|
|
||||||
if ($this->hasRelation($relKey)) {
|
if ($this->hasRelation($relKey)) {
|
||||||
if ($v !== null) {
|
|
||||||
|
if ($this->hasUnresolvedRelatedProperty($k)) {
|
||||||
|
$v = $this->$relKey;
|
||||||
|
} elseif ($v !== null) {
|
||||||
$v = $this->getRelatedObjectName($relKey, $v);
|
$v = $this->getRelatedObjectName($relKey, $v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue