diff --git a/application/forms/BpConfigForm.php b/application/forms/BpConfigForm.php index fc19160..b1847f8 100644 --- a/application/forms/BpConfigForm.php +++ b/application/forms/BpConfigForm.php @@ -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)); + } } } diff --git a/library/Businessprocess/BpConfig.php b/library/Businessprocess/BpConfig.php index 1e3f119..43e8f5b 100644 --- a/library/Businessprocess/BpConfig.php +++ b/library/Businessprocess/BpConfig.php @@ -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;