From 5419d4428c86c488a43124f85e5407d7cbae6541 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:47 +0200 Subject: Adding upstream version 1.11.1. Signed-off-by: Daniel Baumann --- library/Director/Objects/IcingaService.php | 107 +++++------------------------ 1 file changed, 17 insertions(+), 90 deletions(-) (limited to 'library/Director/Objects/IcingaService.php') diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index 9479ef7..cbf9ca5 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -8,7 +8,6 @@ use Icinga\Module\Director\Data\PropertiesFilter; use Icinga\Module\Director\Db; use Icinga\Module\Director\Db\Cache\PrefetchCache; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; -use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; @@ -169,94 +168,6 @@ class IcingaService extends IcingaObject implements ExportInterface } } - /** - * @return object - * @deprecated please use \Icinga\Module\Director\Data\Exporter - * @throws \Icinga\Exception\NotFoundError - */ - public function export() - { - // TODO: ksort in toPlainObject? - $props = (array) $this->toPlainObject(); - $props['fields'] = $this->loadFieldReferences(); - ksort($props); - - return (object) $props; - } - - /** - * @param $plain - * @param Db $db - * @param bool $replace - * @return IcingaService - * @throws DuplicateKeyException - * @throws \Icinga\Exception\NotFoundError - */ - public static function import($plain, Db $db, $replace = false) - { - $properties = (array) $plain; - $name = $properties['object_name']; - if ($properties['object_type'] !== 'template') { - throw new InvalidArgumentException(sprintf( - 'Can import only Templates, got "%s" for "%s"', - $properties['object_type'], - $name - )); - } - $key = [ - 'object_type' => 'template', - 'object_name' => $name - ]; - - if ($replace && static::exists($key, $db)) { - $object = static::load($key, $db); - } elseif (static::exists($key, $db)) { - throw new DuplicateKeyException( - 'Service Template "%s" already exists', - $name - ); - } else { - $object = static::create([], $db); - } - - // $object->newFields = $properties['fields']; - unset($properties['fields']); - $object->setProperties($properties); - - return $object; - } - - /** - * @deprecated please use \Icinga\Module\Director\Data\FieldReferenceLoader - * @return array - */ - protected function loadFieldReferences() - { - $db = $this->getDb(); - - $res = $db->fetchAll( - $db->select()->from([ - 'sf' => 'icinga_service_field' - ], [ - 'sf.datafield_id', - 'sf.is_required', - 'sf.var_filter', - ])->join(['df' => 'director_datafield'], 'df.id = sf.datafield_id', []) - ->where('service_id = ?', $this->get('id')) - ->order('varname ASC') - ); - - if (empty($res)) { - return []; - } else { - foreach ($res as $field) { - $field->datafield_id = (int) $field->datafield_id; - } - - return $res; - } - } - /** * @param string $key * @return $this @@ -473,6 +384,11 @@ class IcingaService extends IcingaObject implements ExportInterface } } + protected function rendersConditionalTemplate(): bool + { + return $this->getRenderingZone() === self::ALL_NON_GLOBAL_ZONES; + } + /** * @return bool */ @@ -667,11 +583,22 @@ class IcingaService extends IcingaObject implements ExportInterface protected function getDefaultZone(IcingaConfig $config = null) { + // Hint: this isn't possible yet, as we're unable to render dependent apply rules to multiple zones as well + // if ($this->isTemplate()) { + // return self::ALL_NON_GLOBAL_ZONES; + // } if ($this->get('host_id') === null) { return parent::getDefaultZone(); } else { - return $this->getRelatedObject('host', $this->get('host_id')) + $zone = $this->getRelatedObject('host', $this->get('host_id')) ->getRenderingZone($config); + + // Hint: this avoids problems with host templates rendered to all non-global zones + if ($zone === self::ALL_NON_GLOBAL_ZONES) { + $zone = $this->connection->getDefaultGlobalZoneName(); + } + + return $zone; } } -- cgit v1.2.3