IcingaObject: move duplicate logic to common func

This commit is contained in:
Thomas Gelf 2016-10-09 13:15:05 +00:00
parent 3423ddf605
commit e96db8b296

View File

@ -1279,15 +1279,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return; return;
} }
$type = $this->getShortTableName(); $filename = $this->getRenderingFilename();
if ($this->isTemplate()) {
$filename = strtolower($type) . '_templates';
} elseif ($this->isApplyRule()) {
$filename = strtolower($type) . '_apply';
} else {
$filename = strtolower($type) . 's';
}
if ($config->isLegacy()) { if ($config->isLegacy()) {
@ -1333,6 +1325,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return; return;
} }
$config->configFile(
'zones.d/' . $this->getRenderingZone($config) . '/' . $this->getRenderingFilename()
)->addObject($this);
}
public function getRenderingFilename()
{
$type = $this->getShortTableName(); $type = $this->getShortTableName();
if ($this->isTemplate()) { if ($this->isTemplate()) {
@ -1343,9 +1342,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$filename = strtolower($type) . 's'; $filename = strtolower($type) . 's';
} }
$config->configFile( return $filename;
'zones.d/' . $this->getRenderingZone($config) . '/' . $filename
)->addObject($this);
} }
public function getRenderingZone(IcingaConfig $config = null) public function getRenderingZone(IcingaConfig $config = null)