Skip to content

Commit

Permalink
IcingaCloneObjectForm: Fix host cloning for director branches
Browse files Browse the repository at this point in the history
The cloned host must also have services and service sets that are under the original host.
  • Loading branch information
raviks789 committed Jul 23, 2024
1 parent 428a49f commit 2e05ae7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions application/forms/IcingaCloneObjectForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 2e05ae7

Please sign in to comment.