From 2e05ae7578551cd7857c5ef29be355a20f4b72ad Mon Sep 17 00:00:00 2001 From: raviks789 Date: Tue, 23 Jul 2024 14:31:23 +0200 Subject: [PATCH] IcingaCloneObjectForm: Fix host cloning for director branches The cloned host must also have services and service sets that are under the original host. --- application/forms/IcingaCloneObjectForm.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/application/forms/IcingaCloneObjectForm.php b/application/forms/IcingaCloneObjectForm.php index 8381eee71..26f560bcb 100644 --- a/application/forms/IcingaCloneObjectForm.php +++ b/application/forms/IcingaCloneObjectForm.php @@ -200,6 +200,7 @@ public function onSuccess() } $store = new DbObjectStore($connection, $this->branch); + $isBranch = $this->branch && $this->branch->isBranch(); if ($store->store($new)) { $newId = $new->get('id'); foreach ($services as $service) { @@ -209,7 +210,11 @@ public function onSuccess() ); if ($new instanceof IcingaHost) { - $clone->set('host_id', $newId); + if ($isBranch) { + $clone->set('host', $newName); + } else { + $clone->set('host_id', $newId); + } } elseif ($new instanceof IcingaServiceSet) { $clone->set('service_set_id', $newId); } @@ -220,7 +225,14 @@ public function onSuccess() $newSet = IcingaServiceSet::fromPlainObject( $set->toPlainObject(), $connection - )->set('host_id', $newId); + ); + + if ($isBranch) { + $newSet->set('host', $newName); + } else { + $newSet->set('host_id', $newId); + } + $store->store($newSet); }