Skip to content

Commit

Permalink
IcingaCloneObjectForm: Fix cloning of hots in 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 48f49ac
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions application/forms/IcingaCloneObjectForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function onSuccess()
$object->getObjectName()
);

if ($object->isTemplate() && $this->branch && $this->branch->isBranch()) {
$isBranch = $this->branch && $this->branch->isBranch();
if ($object->isTemplate() && $isBranch) {
throw new IcingaException('Cloning templates is not available for Branches');
}

Expand Down Expand Up @@ -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 48f49ac

Please sign in to comment.