BusinessProcess, BpNode: improve legacy storage

Before this fix depending on tree structure processes used multiple
times as a sub-node could have been stored multiple times, resulting
in warnings at render time.
This commit is contained in:
Thomas Gelf 2015-10-05 16:40:08 +02:00
parent f5facc02d1
commit 3009a28d3d
2 changed files with 12 additions and 4 deletions

View file

@ -262,6 +262,10 @@ class BpNode extends Node
public function toLegacyConfigString(& $rendered = array())
{
$cfg = '';
if (array_key_exists($this->name, $rendered)) {
return $cfg;
}
$rendered[$this->name] = true;
$children = array();
foreach ($this->getChildren() as $name => $child) {
@ -270,7 +274,6 @@ class BpNode extends Node
if ($child instanceof BpNode) {
$cfg .= $child->toLegacyConfigString($rendered) . "\n";
}
$rendered[$name] = true;
}
$eq = '=';
$op = $this->operator;
@ -278,11 +281,16 @@ class BpNode extends Node
$eq = '= ' . $op . ' of:';
$op = '+';
}
$strChildren = implode(' ' . $op . ' ', $children);
if ((count($children) < 2) && $op !== '&') {
$strChildren = $op . ' ' . $strChildren;
}
$cfg .= sprintf(
"%s %s %s\n",
$this->name,
$eq,
implode(' ' . $op . ' ', $children)
$strChildren
);
if ($this->hasAlias() || $this->getDisplay() > 0) {
$prio = $this->getDisplay();

View file

@ -629,12 +629,12 @@ class BusinessProcess
$rendered = array();
foreach ($this->getChildren() as $child) {
$rendered[(string) $child] = true;
$conf .= $child->toLegacyConfigString($rendered);
$rendered[(string) $child] = true;
}
foreach ($this->getUnboundNodes() as $node) {
$rendered[(string) $node] = true;
$conf .= $node->toLegacyConfigString($rendered);
$rendered[(string) $node] = true;
}
return $conf . "\n";
}