From 1713dee1c1bc2baa8732317fda4c856005b73ce8 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Wed, 13 Feb 2019 11:18:04 +0100 Subject: [PATCH] IcingaServiceSet: Delete host sets when deleting a set This allows service sets to be deleted, including their children sets that are assigned to hosts. The UI forbids deleting those sets, but we can use it like this for CLI and purging during sync. --- library/Director/Objects/IcingaServiceSet.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index c1b0cbacb..42dd6bb8e 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -234,6 +234,19 @@ public static function import($plain, Db $db, $replace = false) return $object; } + public function beforeDelete() + { + // check if this is a template, or directly assigned to a host + if ($this->get('host_id') === null) { + // find all host sets and delete them + foreach ($this->fetchHostSets() as $set) { + $set->delete(); + } + } + + parent::beforeDelete(); + } + /** * @throws \Icinga\Exception\NotFoundError */