Skip to content

Commit

Permalink
* [FIX] Fixed wrong behavior when parsing XML array nodes when the va…
Browse files Browse the repository at this point in the history
…lue is not set. Related #22
  • Loading branch information
nuxsmin committed Apr 21, 2017
1 parent 2b24afb commit 7795d23
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ajax/saveConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion inc/SMD/Core/sysMonDash.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
23 changes: 15 additions & 8 deletions inc/SMD/Storage/XmlHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class XmlHandler implements StorageInterface
/**
* @var mixed
*/
protected $items = null;
protected $items;
/**
* @var string
*/
Expand Down Expand Up @@ -95,7 +95,6 @@ public function load($tag = 'root')

/**
* Comprobar que el archivo existe y se puede leer/escribir
*
* @return bool
*/
protected function checkSourceFile()
Expand All @@ -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);
Expand All @@ -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;
}

}
}
}
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion inc/SMD/Util/Util.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function checkRefreshSession()
*/
public static function getVersion($retBuild = false)
{
$build = 2017041201;
$build = 2017042101;
$version = array(1, 1);

if ($retBuild) {
Expand Down

0 comments on commit 7795d23

Please sign in to comment.