mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 00:34:05 +02:00
IcingaObject: reduce duplicate code
This commit is contained in:
parent
a80bc13f39
commit
00db8a6204
@ -1624,6 +1624,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
return $filename;
|
||||
}
|
||||
|
||||
protected function getNameForZoneId($zoneId, IcingaConfig $config = null)
|
||||
{
|
||||
// TODO: this is still ugly.
|
||||
if ($config === null) {
|
||||
return IcingaZone::loadWithAutoIncId(
|
||||
$zoneId,
|
||||
$this->getConnection()
|
||||
)->getObjectName();
|
||||
} else {
|
||||
// Config has a lookup cache, is faster:
|
||||
return $config->getZoneName($zoneId);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRenderingZone(IcingaConfig $config = null)
|
||||
{
|
||||
if ($this->hasUnresolvedRelatedProperty('zone_id')) {
|
||||
@ -1633,30 +1647,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
if ($this->hasProperty('zone_id')) {
|
||||
if (! $this->supportsImports()) {
|
||||
if ($zoneId = $this->get('zone_id')) {
|
||||
// TODO: this is ugly.
|
||||
if ($config === null) {
|
||||
return IcingaZone::loadWithAutoIncId(
|
||||
$zoneId,
|
||||
$this->getConnection()
|
||||
)->getObjectName();
|
||||
} else {
|
||||
// Config has a lookup cache, is faster:
|
||||
return $config->getZoneName($zoneId);
|
||||
}
|
||||
return $this->getNameForZoneId($zoneId, $config);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if ($zoneId = $this->getSingleResolvedProperty('zone_id')) {
|
||||
if ($config === null) {
|
||||
return IcingaZone::loadWithAutoIncId(
|
||||
$zoneId,
|
||||
$this->getConnection()
|
||||
)->getObjectName();
|
||||
} else {
|
||||
// Config has a lookup cache, is faster:
|
||||
return $config->getZoneName($zoneId);
|
||||
}
|
||||
return $this->getNameForZoneId($zoneId, $config);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return self::RESOLVE_ERROR;
|
||||
|
Loading…
x
Reference in New Issue
Block a user