AddNode: fix creating nested nodes

fixes #13883
This commit is contained in:
Thomas Gelf 2017-01-11 17:38:19 +01:00
parent c083b117dd
commit 5f6b35906d
4 changed files with 23 additions and 12 deletions

View file

@ -383,11 +383,12 @@ class AddNodeForm extends QuickForm
case 'new-process':
$properties = $this->getValues();
unset($properties['name']);
$properties['parentName'] = $this->parent->getName();
$changes->createNode($this->getValue('name'), $properties);
break;
}
// Trigger session desctruction to make sure it get's stored.
// Trigger session destruction to make sure it get's stored.
// TODO: figure out why this is necessary, might be an unclean shutdown on redirect
unset($changes);

View file

@ -104,7 +104,7 @@ class BpNode extends Node
$this->getChildren();
}
$name = (string) $node;
$name = $node->getName();
if (array_key_exists($name, $this->children)) {
throw new ConfigurationError(
'Node "%s" has been defined more than once',

View file

@ -36,14 +36,23 @@ class NodeAddChildrenAction extends NodeAction
// be a different action
return $this;
}
$node = $bp->getNode($this->getNodeName());
$existing = $node->getChildNames();
$node = $config->getBpNode($this->getNodeName());
foreach ($this->children as $name) {
if (! in_array($name, $existing)) {
$existing[] = $name;
if (! $config->hasNode($name)) {
if (strpos($name, ';') !== false) {
list($host, $service) = preg_split('/;/', $name, 2);
if ($service === 'Hoststatus') {
$config->createHost($host);
} else {
$config->createService($host, $service);
}
}
}
$node->addChild($config->getNode($name));
}
$node->setChildNames($existing);
return $this;
}

View file

@ -91,17 +91,18 @@ class NodeCreateAction extends NodeAction
} else {
$properties['child_names'] = array();
}
$node = new BpNode($bp, (object) $properties);
$node = new BpNode($config, (object) $properties);
foreach ($this->getProperties() as $key => $val) {
if ($key === 'parentName') {
$config->getBpNode($val)->addChild($node);
continue;
}
$func = 'set' . ucfirst($key);
$node->$func($val);
}
$bp->addNode($name, $node);
if ($this->hasParent()) {
$node->addParent($bp->getNode($this->getParentName()));
}
$config->addNode($name, $node);
return $node;
}