IcingaService(Legacy): Fix duplicated rendering of apply

refs #13049
This commit is contained in:
Markus Frosch 2016-11-15 10:52:03 +01:00
parent b40cfd5f05
commit 4e5dfb097e

View File

@ -194,9 +194,11 @@ class IcingaService extends IcingaObject
{ {
$conn = $this->getConnection(); $conn = $this->getConnection();
$filter = Filter::fromQueryString($this->get('assign_filter')); $assign_filter = $this->get('assign_filter');
$filter = Filter::fromQueryString($assign_filter);
$hosts = HostApplyMatches::forFilter($filter, $conn); $hosts = HostApplyMatches::forFilter($filter, $conn);
$this->set('object_type', 'object'); $this->set('object_type', 'object');
$this->set('assign_filter', null);
foreach ($hosts as $hostname) { foreach ($hosts as $hostname) {
$file = $this->legacyHostnameServicesFile($hostname, $config); $file = $this->legacyHostnameServicesFile($hostname, $config);
@ -206,6 +208,7 @@ class IcingaService extends IcingaObject
$this->set('host', null); $this->set('host', null);
$this->set('object_type', 'apply'); $this->set('object_type', 'apply');
$this->set('assign_filter', $assign_filter);
} }
protected function legacyHostnameServicesFile($hostname, IcingaConfig $config) protected function legacyHostnameServicesFile($hostname, IcingaConfig $config)
@ -223,8 +226,8 @@ class IcingaService extends IcingaObject
return ''; return '';
} }
if ($this->get('assign_filter') !== null) { if ($this->isApplyRule()) {
return $this->renderLegacyResolvedAssignFilter(); throw new ProgrammingError('Apply Services can not be rendered directly.');
} }
$str = parent::toLegacyConfigString(); $str = parent::toLegacyConfigString();
@ -239,24 +242,6 @@ class IcingaService extends IcingaObject
} }
} }
protected function renderLegacyResolvedAssignFilter()
{
$str = '';
$hosts = HostApplyMatches::forFilter(
Filter::fromQueryString($this->get('assign_filter')),
$this->getConnection()
);
$this->object_type = 'object';
$this->assign_filter = null;
foreach ($hosts as $hostname) {
$this->host = $hostname;
$str .= $this->toLegacyConfigString();
}
return $str;
}
public function toConfigString() public function toConfigString()
{ {
if ($this->get('service_set_id')) { if ($this->get('service_set_id')) {