Allow cloning service sets in Director Branches

This commit is contained in:
raviks789 2024-07-23 11:21:48 +02:00 committed by Eric Lippmann
parent d56ca2c235
commit 6c766dff43
2 changed files with 25 additions and 8 deletions

View File

@ -29,7 +29,12 @@ class IcingaCloneObjectForm extends DirectorForm
{
$isBranch = $this->branch && $this->branch->isBranch();
$branchOnly = $this->object->get('id') === null;
if ($isBranch && $this->object instanceof IcingaObject && $this->object->isTemplate()) {
if (
$isBranch
&& $this->object->isTemplate()
&& ! $this->object instanceof IcingaServiceSet
) {
$this->addHtml(Hint::error($this->translate(
'Templates cannot be cloned in Configuration Branches'
)));
@ -149,7 +154,12 @@ class IcingaCloneObjectForm extends DirectorForm
);
$isBranch = $this->branch && $this->branch->isBranch();
if ($object->isTemplate() && $isBranch) {
if (
$isBranch
&& $this->object->isTemplate()
&& ! $this->object instanceof IcingaServiceSet
) {
throw new IcingaException('Cloning templates is not available for Branches');
}
@ -218,8 +228,13 @@ class IcingaCloneObjectForm extends DirectorForm
$clone->set('host_id', $newId);
}
} elseif ($new instanceof IcingaServiceSet) {
$clone->set('service_set_id', $newId);
if ($isBranch) {
$clone->set('service_set', $newName);
} else {
$clone->set('service_set_id', $newId);
}
}
$store->store($clone);
}

View File

@ -218,12 +218,14 @@ abstract class ObjectController extends ActionController
$this->addTitle($this->translate('Clone: %s'), $object->getObjectName())
->addBackToObjectLink();
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Templates'))) {
return;
}
if (! $object instanceof IcingaServiceSet) {
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Templates'))) {
return;
}
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Apply Rules'))) {
return;
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Apply Rules'))) {
return;
}
}
$form = IcingaCloneObjectForm::load()