mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-26 01:19:33 -05:00
Merge pull request #157 from Icinga/bugfix/new-node-self-reference-149
Prevent circular node references
This commit is contained in:
commit
2fd3011978
1 changed files with 22 additions and 2 deletions
|
|
@ -327,9 +327,15 @@ class AddNodeForm extends QuickForm
|
|||
{
|
||||
$list = array();
|
||||
|
||||
$parents = array();
|
||||
|
||||
if ($this->hasParentNode()) {
|
||||
$this->collectAllParents($this->parent, $parents);
|
||||
$parents[$this->parent->getName()] = $this->parent;
|
||||
}
|
||||
|
||||
foreach ($this->bp->getNodes() as $node) {
|
||||
if ($node instanceof BpNode) {
|
||||
// TODO: Blacklist parents
|
||||
if ($node instanceof BpNode && ! isset($parents[$node->getName()])) {
|
||||
$list[(string) $node] = (string) $node; // display name?
|
||||
}
|
||||
}
|
||||
|
|
@ -338,6 +344,20 @@ class AddNodeForm extends QuickForm
|
|||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the given node's parents recursively into the given array by their names
|
||||
*
|
||||
* @param BpNode $node
|
||||
* @param BpNode[] $parents
|
||||
*/
|
||||
protected function collectAllParents(BpNode $node, array & $parents)
|
||||
{
|
||||
foreach ($node->getParents() as $parent) {
|
||||
$parents[$parent->getName()] = $parent;
|
||||
$this->collectAllParents($parent, $parents);
|
||||
}
|
||||
}
|
||||
|
||||
protected function fetchObjectList()
|
||||
{
|
||||
$this->objectList = array();
|
||||
|
|
|
|||
Loading…
Reference in a new issue