From 8465bc0bc3c9f828201538395e25f71d1faf13a3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 21 Feb 2019 08:11:59 +0100 Subject: [PATCH] LegacyConfigParser: Establish parent-child relationships This replaces commit d1f32c5 as this is the more efficient and proper solution. refs #134 --- application/controllers/NodeController.php | 9 ---- .../Storage/LegacyConfigParser.php | 44 ++++++++----------- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/application/controllers/NodeController.php b/application/controllers/NodeController.php index 1d8fe0a..d557050 100644 --- a/application/controllers/NodeController.php +++ b/application/controllers/NodeController.php @@ -25,15 +25,6 @@ class NodeController extends Controller foreach ($this->storage()->listProcessNames() as $configName) { $config = $this->storage()->loadProcess($configName); - // TODO: Fix issues with children, they do not exist unless resolved :-/ - // This is a workaround: - foreach ($config->getRootNodes() as $node) { - $node->getState(); - } - foreach ($config->getRootNodes() as $node) { - $node->clearState(); - } - if (! $config->hasNode($name)) { continue; } diff --git a/library/Businessprocess/Storage/LegacyConfigParser.php b/library/Businessprocess/Storage/LegacyConfigParser.php index ddcdb29..ca7b170 100644 --- a/library/Businessprocess/Storage/LegacyConfigParser.php +++ b/library/Businessprocess/Storage/LegacyConfigParser.php @@ -298,48 +298,42 @@ class LegacyConfigParser // New feature: $minWarn = $m[2]; $value = $m[3]; } - $cmps = preg_split('~\s*\\' . $op . '\s*~', $value, -1, PREG_SPLIT_NO_EMPTY); - $childNames = array(); + $node = new BpNode((object) array( + 'name' => $name, + 'operator' => $op_name, + 'child_names' => [] + )); + $node->setBpConfig($bp); + + $cmps = preg_split('~\s*\\' . $op . '\s*~', $value, -1, PREG_SPLIT_NO_EMPTY); foreach ($cmps as $val) { if (strpos($val, ';') !== false) { if ($bp->hasNode($val)) { - $childNames[] = $val; - continue; - } - - list($host, $service) = preg_split('~;~', $val, 2); - if ($service === 'Hoststatus') { - $bp->createHost($host); + $node->addChild($bp->getNode($val)); } else { - $bp->createService($host, $service); + list($host, $service) = preg_split('~;~', $val, 2); + if ($service === 'Hoststatus') { + $node->addChild($bp->createHost($host)); + } else { + $node->addChild($bp->createService($host, $service)); + } } - } - if ($val[0] === '@') { + } elseif ($val[0] === '@') { if (strpos($val, ':') === false) { throw new ConfigurationError( "I'm unable to import full external configs, a node needs to be provided for '%s'", $val ); - // TODO: this might work: - // $node = $bp->createImportedNode(substr($val, 1)); } else { list($config, $nodeName) = preg_split('~:\s*~', substr($val, 1), 2); - $node = $bp->createImportedNode($config, $nodeName); + $node->addChild($bp->createImportedNode($config, $nodeName)); } - $val = $node->getName(); + } else { + $node->addChild($bp->getNode($val)); } - - $childNames[] = $val; } - $node = new BpNode((object) array( - 'name' => $name, - 'operator' => $op_name, - 'child_names' => $childNames - )); - $node->setBpConfig($bp); - $bp->addNode($name, $node); }