From 7795d238a145e56acfbcc15034830e3257bef76e Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Fri, 21 Apr 2017 13:46:02 +0200 Subject: [PATCH] * [FIX] Fixed wrong behavior when parsing XML array nodes when the value is not set. Related #22 --- ajax/saveConfig.php | 2 +- inc/SMD/Core/sysMonDash.class.php | 2 +- inc/SMD/Storage/XmlHandler.class.php | 23 +++++++++++++++-------- inc/SMD/Util/Util.class.php | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ajax/saveConfig.php b/ajax/saveConfig.php index 3c44ae5..d46841b 100644 --- a/ajax/saveConfig.php +++ b/ajax/saveConfig.php @@ -88,7 +88,7 @@ $ConfigData->setShowScheduled($showScheduled); $ConfigData->setRegexHostShow($regexHostShow); $ConfigData->setRegexServiceNoShow($regexServicesNoShow); -$ConfigData->setCriticalItems(explode(',', $criticalItems)); +$ConfigData->setCriticalItems(!empty($criticalItems) ? explode(',', $criticalItems) : []); $ConfigData->setBackend($Backends); $ConfigData->setClientURL($specialClientURL); $ConfigData->setRemoteServer($specialRemoteServerURL); diff --git a/inc/SMD/Core/sysMonDash.class.php b/inc/SMD/Core/sysMonDash.class.php index d6fae63..18f97d3 100644 --- a/inc/SMD/Core/sysMonDash.class.php +++ b/inc/SMD/Core/sysMonDash.class.php @@ -201,7 +201,7 @@ public function getBackends() */ private function filterItems(EventInterface $item) { - if (count($this->Config->getCriticalItems()) > 1) { + if (count($this->Config->getCriticalItems()) > 0) { return $this->getFilterCritical($item); } diff --git a/inc/SMD/Storage/XmlHandler.class.php b/inc/SMD/Storage/XmlHandler.class.php index bda6f30..d229465 100644 --- a/inc/SMD/Storage/XmlHandler.class.php +++ b/inc/SMD/Storage/XmlHandler.class.php @@ -39,7 +39,7 @@ class XmlHandler implements StorageInterface /** * @var mixed */ - protected $items = null; + protected $items; /** * @var string */ @@ -95,7 +95,6 @@ public function load($tag = 'root') /** * Comprobar que el archivo existe y se puede leer/escribir - * * @return bool */ protected function checkSourceFile() @@ -114,7 +113,7 @@ protected function readChildNodes(DOMNodeList $NodeList) $nodes = array(); foreach ($NodeList as $node) { - /** @var $node DOMNode */ + /** @var $node DOMNode|DOMElement */ if (is_object($node->childNodes) && $node->childNodes->length > 1) { if ($node->nodeName === 'item') { $nodes[] = $this->readChildNodes($node->childNodes); @@ -127,7 +126,12 @@ protected function readChildNodes(DOMNodeList $NodeList) if ($node->nodeName === 'item') { $nodes[] = $val; } else { - $nodes[$node->nodeName] = $val; + if ($node->hasAttributes() && $node->getAttribute('type') === 'array') { + $nodes[$node->nodeName] = []; + } else { + $nodes[$node->nodeName] = $val; + } + } } } @@ -143,7 +147,7 @@ protected function readChildNodes(DOMNodeList $NodeList) */ public function __get($id) { - return $this->items[$id]; + return isset($this->items[$id]) ? $this->items[$id] : null; } /** @@ -187,10 +191,13 @@ protected function writeChildNodes($items, DOMNode $Node, $type = null) } if (is_array($value)) { + $newNode->setAttribute('type', 'array'); + if (count($value) > 0) { $this->writeChildNodes($value, $newNode, $key); + } } elseif (is_object($value)) { - $newNode->setAttribute('class', get_class($value)); - $newNode->appendChild($this->Dom->createTextNode(base64_encode(serialize($value)))); + $newNode->setAttribute('class', get_class($value)); + $newNode->appendChild($this->Dom->createTextNode(base64_encode(serialize($value)))); } else { $newNode->appendChild($this->Dom->createTextNode(trim($value))); } @@ -237,7 +244,7 @@ protected function analyzeObject($object) $property->setAccessible(true); $value = $property->getValue($object); - if (is_numeric($value) || is_bool($value)){ + if (is_numeric($value) || is_bool($value)) { $items[$property->getName()] = (int)$value; } else { $items[$property->getName()] = $value; diff --git a/inc/SMD/Util/Util.class.php b/inc/SMD/Util/Util.class.php index 09a167b..a9f457a 100644 --- a/inc/SMD/Util/Util.class.php +++ b/inc/SMD/Util/Util.class.php @@ -132,7 +132,7 @@ public static function checkRefreshSession() */ public static function getVersion($retBuild = false) { - $build = 2017041201; + $build = 2017042101; $version = array(1, 1); if ($retBuild) {