Merge pull request #157 from Icinga/bugfix/new-node-self-reference-149

Prevent circular node references
This commit is contained in:
Eric Lippmann 2018-06-26 10:54:53 +02:00 committed by GitHub
commit 2fd3011978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();