Skip to content

Commit

Permalink
AddNode: fix creating nested nodes
Browse files Browse the repository at this point in the history
fixes #13883
  • Loading branch information
Thomas-Gelf committed Jan 11, 2017
1 parent c083b11 commit 5f6b359
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion application/forms/AddNodeForm.php
Expand Up @@ -383,11 +383,12 @@ public function onSuccess()
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);

Expand Down
2 changes: 1 addition & 1 deletion library/Businessprocess/BpNode.php
Expand Up @@ -104,7 +104,7 @@ public function addChild(Node $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',
Expand Down
19 changes: 14 additions & 5 deletions library/Businessprocess/Modification/NodeAddChildrenAction.php
Expand Up @@ -36,14 +36,23 @@ public function applyTo(BpConfig $config)
// 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;
}
Expand Down
11 changes: 6 additions & 5 deletions library/Businessprocess/Modification/NodeCreateAction.php
Expand Up @@ -91,17 +91,18 @@ public function applyTo(BpConfig $config)
} 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;
}
Expand Down

0 comments on commit 5f6b359

Please sign in to comment.