IcingaCloneObjectForm: Fix cloning of hosts in director branches (#2898)

The cloned host must also have services and service sets that are under
the original host.
This commit is contained in:
Eric Lippmann 2024-11-07 12:57:02 +01:00 committed by GitHub
commit 030740942e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 3 deletions

View File

@ -148,7 +148,8 @@ class IcingaCloneObjectForm extends DirectorForm
$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');
}
@ -211,7 +212,11 @@ class IcingaCloneObjectForm extends DirectorForm
);
if ($new instanceof IcingaHost) {
if ($isBranch) {
$clone->set('host', $newName);
} else {
$clone->set('host_id', $newId);
}
} elseif ($new instanceof IcingaServiceSet) {
$clone->set('service_set_id', $newId);
}
@ -222,7 +227,14 @@ class IcingaCloneObjectForm extends DirectorForm
$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);
}