From 00db8a6204f2a1a0b1f2bd29720ef73d4cc44503 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 8 Jun 2018 18:11:42 +0200 Subject: [PATCH] IcingaObject: reduce duplicate code --- library/Director/Objects/IcingaObject.php | 35 +++++++++++------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index c1507bf5..2c8df7a3 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -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;