IcingaObject: reduce duplicate code

This commit is contained in:
Thomas Gelf 2018-06-08 18:11:42 +02:00
parent a80bc13f39
commit 00db8a6204

View File

@ -1624,6 +1624,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $filename; 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) public function getRenderingZone(IcingaConfig $config = null)
{ {
if ($this->hasUnresolvedRelatedProperty('zone_id')) { if ($this->hasUnresolvedRelatedProperty('zone_id')) {
@ -1633,30 +1647,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
if ($this->hasProperty('zone_id')) { if ($this->hasProperty('zone_id')) {
if (! $this->supportsImports()) { if (! $this->supportsImports()) {
if ($zoneId = $this->get('zone_id')) { if ($zoneId = $this->get('zone_id')) {
// TODO: this is ugly. return $this->getNameForZoneId($zoneId, $config);
if ($config === null) {
return IcingaZone::loadWithAutoIncId(
$zoneId,
$this->getConnection()
)->getObjectName();
} else {
// Config has a lookup cache, is faster:
return $config->getZoneName($zoneId);
}
} }
} }
try { try {
if ($zoneId = $this->getSingleResolvedProperty('zone_id')) { if ($zoneId = $this->getSingleResolvedProperty('zone_id')) {
if ($config === null) { return $this->getNameForZoneId($zoneId, $config);
return IcingaZone::loadWithAutoIncId(
$zoneId,
$this->getConnection()
)->getObjectName();
} else {
// Config has a lookup cache, is faster:
return $config->getZoneName($zoneId);
}
} }
} catch (Exception $e) { } catch (Exception $e) {
return self::RESOLVE_ERROR; return self::RESOLVE_ERROR;