mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
IcingaDependency: cleanup, shorten custom logic
This commit is contained in:
parent
de0b3db8a2
commit
05d5152e6f
@ -321,7 +321,7 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
{
|
{
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
return c::renderKeyValue(
|
return c::renderKeyValue(
|
||||||
'parent_host',
|
'parent_host_name',
|
||||||
$this->get('parent_host_var')
|
$this->get('parent_host_var')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -378,14 +378,24 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
{
|
{
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
return c::renderKeyValue(
|
return c::renderKeyValue(
|
||||||
'parent_service',
|
'parent_service_name',
|
||||||
$this->get('parent_host_var')
|
$this->get('parent_host_var')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//special case for parent service set as plain string for Apply rules
|
//
|
||||||
|
/**
|
||||||
|
* Render parent_service_var as parent_service_name
|
||||||
|
*
|
||||||
|
* Special case for parent service set as plain string for Apply rules
|
||||||
|
*
|
||||||
|
* @codingStandardsIgnoreStart
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function renderParent_service_by_name()
|
public function renderParent_service_by_name()
|
||||||
{
|
{
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
return c::renderKeyValue(
|
return c::renderKeyValue(
|
||||||
'parent_service_name',
|
'parent_service_name',
|
||||||
c::renderString($this->get('parent_service_by_name'))
|
c::renderString($this->get('parent_service_by_name'))
|
||||||
@ -412,7 +422,7 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
$objKey = $this->unresolvedRelatedProperties[$name];
|
$objKey = $this->unresolvedRelatedProperties[$name];
|
||||||
|
|
||||||
# related services need array key
|
# related services need array key
|
||||||
if ($class == "Icinga\Module\Director\Objects\IcingaService" ) {
|
if ($class === IcingaService::class) {
|
||||||
if ($name === 'parent_service_id' && $this->object_type === 'apply') {
|
if ($name === 'parent_service_id' && $this->object_type === 'apply') {
|
||||||
//special case , parent service can be set as simple string for Apply
|
//special case , parent service can be set as simple string for Apply
|
||||||
if ($this->properties['parent_host_id'] === null) {
|
if ($this->properties['parent_host_id'] === null) {
|
||||||
@ -521,27 +531,15 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
|
|
||||||
protected function getRelatedProperty($key)
|
protected function getRelatedProperty($key)
|
||||||
{
|
{
|
||||||
$idKey = $key . '_id';
|
$related = parent::getRelatedProperty($key);
|
||||||
if ($this->hasUnresolvedRelatedProperty($idKey)) {
|
|
||||||
return $this->unresolvedRelatedProperties[$idKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($id = $this->get($idKey)) {
|
|
||||||
/** @var IcingaObject $class */
|
|
||||||
$class = $this->getRelationClass($key);
|
|
||||||
$object = $class::loadWithAutoIncId($id, $this->connection);
|
|
||||||
|
|
||||||
return $object->getObjectName();
|
|
||||||
} else {
|
|
||||||
// handle special case for plain string parent service on Dependency
|
// handle special case for plain string parent service on Dependency
|
||||||
// Apply rules
|
// Apply rules
|
||||||
if ($key === 'parent_service'
|
if ($related === null && $key === 'parent_service'
|
||||||
&& null !== $this->get('parent_service_by_name')
|
&& null !== $this->get('parent_service_by_name')
|
||||||
) {
|
) {
|
||||||
return $this->get('parent_service_by_name');
|
return $this->get('parent_service_by_name');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return $related;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user