mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
Prevent deletion of referenced BP config
This commit is contained in:
parent
3a7dc64a50
commit
da2ed1aef4
2 changed files with 27 additions and 4 deletions
|
|
@ -149,10 +149,17 @@ class BpConfigForm extends BpConfigBaseForm
|
|||
$name = $this->getValue('name');
|
||||
|
||||
if ($this->shouldBeDeleted()) {
|
||||
$this->config->clearAppliedChanges();
|
||||
$this->storage->deleteProcess($name);
|
||||
$this->setSuccessUrl('businessprocess');
|
||||
$this->redirectOnSuccess(sprintf('Process %s has been deleted', $name));
|
||||
if ($this->config->isReferenced()) {
|
||||
$this->addError(sprintf(
|
||||
$this->translate('Process "%s" cannot be deleted as it has been referenced in other processes'),
|
||||
$name
|
||||
));
|
||||
} else {
|
||||
$this->config->clearAppliedChanges();
|
||||
$this->storage->deleteProcess($name);
|
||||
$this->setSuccessUrl('businessprocess');
|
||||
$this->redirectOnSuccess(sprintf('Process %s has been deleted', $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -305,6 +305,22 @@ class BpConfig
|
|||
return $this->backend;
|
||||
}
|
||||
|
||||
public function isReferenced()
|
||||
{
|
||||
foreach ($this->storage()->listProcessNames() as $bpName) {
|
||||
if ($bpName !== $this->getName()) {
|
||||
$bp = $this->storage()->loadProcess($bpName);
|
||||
foreach ($bp->getImportedNodes() as $importedNode) {
|
||||
if ($importedNode->getConfigName() === $this->getName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasBackend()
|
||||
{
|
||||
return $this->backend !== null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue