Skip to content

Commit

Permalink
IcingaService(Legacy): Fix duplicated rendering of apply
Browse files Browse the repository at this point in the history
refs #13049
  • Loading branch information
lazyfrosch committed Nov 15, 2016
1 parent b40cfd5 commit 4e5dfb0
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions library/Director/Objects/IcingaService.php
Expand Up @@ -194,9 +194,11 @@ protected function renderLegacyApplyToConfig(IcingaConfig $config)
{
$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);
$this->set('object_type', 'object');
$this->set('assign_filter', null);

foreach ($hosts as $hostname) {
$file = $this->legacyHostnameServicesFile($hostname, $config);
Expand All @@ -206,6 +208,7 @@ protected function renderLegacyApplyToConfig(IcingaConfig $config)

$this->set('host', null);
$this->set('object_type', 'apply');
$this->set('assign_filter', $assign_filter);
}

protected function legacyHostnameServicesFile($hostname, IcingaConfig $config)
Expand All @@ -223,8 +226,8 @@ public function toLegacyConfigString()
return '';
}

if ($this->get('assign_filter') !== null) {
return $this->renderLegacyResolvedAssignFilter();
if ($this->isApplyRule()) {
throw new ProgrammingError('Apply Services can not be rendered directly.');
}

$str = parent::toLegacyConfigString();
Expand All @@ -239,24 +242,6 @@ public function toLegacyConfigString()
}
}

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()
{
if ($this->get('service_set_id')) {
Expand Down

0 comments on commit 4e5dfb0

Please sign in to comment.