Skip to content

Commit

Permalink
IcingaCloneObjectForm: Fix cloning of hosts in director branches (#2898)
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
lippserd authored Nov 7, 2024
2 parents d9b3b23 + 9d18663 commit 0307409
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 @@ -148,7 +148,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 @@ -211,7 +212,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 @@ -222,7 +227,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 0307409

Please sign in to comment.