From 3103616d1e791a8a6f34eeb16ce2845e21e548e5 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Mon, 28 May 2018 17:15:55 +0300 Subject: [PATCH 1/3] fix(global): deprecated function, PHP notices replace using of deprecated each() function with foreach(), fix several PHP notices related with undefined index Resolves CP7M-51 --- lib/Centreon/Cache/Manager/Manager.php | 2 +- lib/Zend/Cache/Backend.php | 4 ++-- lib/Zend/Cache/Core.php | 4 ++-- lib/Zend/Cache/Frontend/Class.php | 2 +- lib/Zend/Cache/Frontend/File.php | 2 +- lib/Zend/Cache/Frontend/Function.php | 2 +- lib/Zend/Cache/Frontend/Page.php | 2 +- www/class/centreon-clapi/centreonAPI.class.php | 4 ++++ .../centreon-clapi/centreonExported.class.php | 2 +- www/class/centreon-clapi/centreonHost.class.php | 11 ++++++++--- .../centreonServiceTemplate.class.php | 14 ++++++++++---- 11 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/Centreon/Cache/Manager/Manager.php b/lib/Centreon/Cache/Manager/Manager.php index 1278baf3f32..edf34ba822e 100644 --- a/lib/Centreon/Cache/Manager/Manager.php +++ b/lib/Centreon/Cache/Manager/Manager.php @@ -69,7 +69,7 @@ public static function factory($instanceName = "cache", $lifetime = 60, $cacheDi * @param array $sqlParams * @return string */ - public function getCacheFileName($sqlQuery, $sqlParams = array()) + public static function getCacheFileName($sqlQuery, $sqlParams = array()) { $paramString = implode(",", $sqlParams); return md5($sqlQuery.$paramString); diff --git a/lib/Zend/Cache/Backend.php b/lib/Zend/Cache/Backend.php index 320a82f1807..816c739be31 100644 --- a/lib/Zend/Cache/Backend.php +++ b/lib/Zend/Cache/Backend.php @@ -63,7 +63,7 @@ class Zend_Cache_Backend */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } } @@ -78,7 +78,7 @@ public function __construct(array $options = array()) public function setDirectives($directives) { if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); - while (list($name, $value) = each($directives)) { + foreach ($directives as $name => $value) { if (!is_string($name)) { Zend_Cache::throwException("Incorrect option name : $name"); } diff --git a/lib/Zend/Cache/Core.php b/lib/Zend/Cache/Core.php index f43587ecdf5..60ab8e22cf3 100644 --- a/lib/Zend/Cache/Core.php +++ b/lib/Zend/Cache/Core.php @@ -143,7 +143,7 @@ public function __construct($options = array()) Zend_Cache::throwException("Options passed were not an array" . " or Zend_Config instance."); } - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } $this->_loggerSanity(); @@ -158,7 +158,7 @@ public function __construct($options = array()) public function setConfig(Zend_Config $config) { $options = $config->toArray(); - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } return $this; diff --git a/lib/Zend/Cache/Frontend/Class.php b/lib/Zend/Cache/Frontend/Class.php index 20e392805e0..c3c7234d857 100644 --- a/lib/Zend/Cache/Frontend/Class.php +++ b/lib/Zend/Cache/Frontend/Class.php @@ -107,7 +107,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } if ($this->_specificOptions['cached_entity'] === null) { diff --git a/lib/Zend/Cache/Frontend/File.php b/lib/Zend/Cache/Frontend/File.php index c0e34b5513c..c036cf2ad33 100644 --- a/lib/Zend/Cache/Frontend/File.php +++ b/lib/Zend/Cache/Frontend/File.php @@ -88,7 +88,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } if (!isset($this->_specificOptions['master_files'])) { diff --git a/lib/Zend/Cache/Frontend/Function.php b/lib/Zend/Cache/Frontend/Function.php index 4877fbd169f..c04178065ea 100644 --- a/lib/Zend/Cache/Frontend/Function.php +++ b/lib/Zend/Cache/Frontend/Function.php @@ -63,7 +63,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $this->setOption($name, $value); } $this->setOption('automatic_serialization', true); diff --git a/lib/Zend/Cache/Frontend/Page.php b/lib/Zend/Cache/Frontend/Page.php index e29924f80d4..7805d9f19a9 100644 --- a/lib/Zend/Cache/Frontend/Page.php +++ b/lib/Zend/Cache/Frontend/Page.php @@ -129,7 +129,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core */ public function __construct(array $options = array()) { - while (list($name, $value) = each($options)) { + foreach ($options as $name => $value) { $name = strtolower($name); switch ($name) { case 'regexps': diff --git a/www/class/centreon-clapi/centreonAPI.class.php b/www/class/centreon-clapi/centreonAPI.class.php index c4c75cec215..25cde5d66a7 100644 --- a/www/class/centreon-clapi/centreonAPI.class.php +++ b/www/class/centreon-clapi/centreonAPI.class.php @@ -867,6 +867,10 @@ public function export() } foreach ($selected as $select) { $splits = explode(';', $select); + + $splits[0] = isset($splits[0]) ? $splits[0] : null; + $splits[1] = isset($splits[1]) ? $splits[1] : null; + if (!isset($this->objectTable[$splits[0]])) { print "Unknown object : $splits[0]\n"; $this->setReturnCode(1); diff --git a/www/class/centreon-clapi/centreonExported.class.php b/www/class/centreon-clapi/centreonExported.class.php index d046c2d9935..e47328231fa 100644 --- a/www/class/centreon-clapi/centreonExported.class.php +++ b/www/class/centreon-clapi/centreonExported.class.php @@ -138,7 +138,7 @@ public function is_exported($object, $id, $name) return 1; } - if (!is_array($this->exported[$object])) { + if (!isset($this->exported[$object]) || !is_array($this->exported[$object])) { $this->exported[$object] = array(); } $this->exported[$object][$id] = 1; diff --git a/www/class/centreon-clapi/centreonHost.class.php b/www/class/centreon-clapi/centreonHost.class.php index 01e7b0314c8..4a44c3f6b15 100644 --- a/www/class/centreon-clapi/centreonHost.class.php +++ b/www/class/centreon-clapi/centreonHost.class.php @@ -1120,6 +1120,7 @@ protected function getHostListByParent(&$elements) public function export($filters = null) { $filters["host_register"] = $this->register; + $filters['host_id'] = isset($filters['host_id']) ? $filters['host_id'] : null; $elements = $this->object->getList("*", -1, 0, null, null, $filters, "AND"); $extendedObj = new \Centreon_Object_Host_Extended($this->dependencyInjector); $commandObj = new \Centreon_Object_Command($this->dependencyInjector); @@ -1153,7 +1154,7 @@ public function export($filters = null) } } } - if ($param != "hostgroup" && $param != "template") { + if (isset($element[$param]) && $param != "hostgroup" && $param != "template") { $addStr .= $element[$param]; } } @@ -1200,7 +1201,7 @@ public function export($filters = null) echo $this->action . $this->delim . "addparent" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim - . $elements[$parentId][$this->object->getUniqueLabelField()] . "\n"; + . isset($elements[$parentId]) && isset($elements[$parentId][$this->object->getUniqueLabelField()]) ? $elements[$parentId][$this->object->getUniqueLabelField()] : '' . "\n"; } } @@ -1286,7 +1287,11 @@ public function export($filters = null) "AND" ); foreach ($elements as $element) { - $this->api->export_filter('CONTACT', $element['contact_id'], $element['contact_name']); + $exportContactId = isset($element['contact_id']) ? $element['contact_id'] : null; + $exportContactName = isset($element['contact_name']) ? $element['contact_name'] : null; + + $this->api->export_filter('CONTACT', $exportContactId, $exportContactName); + echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim diff --git a/www/class/centreon-clapi/centreonServiceTemplate.class.php b/www/class/centreon-clapi/centreonServiceTemplate.class.php index 124308b668c..7a92e11617c 100644 --- a/www/class/centreon-clapi/centreonServiceTemplate.class.php +++ b/www/class/centreon-clapi/centreonServiceTemplate.class.php @@ -907,7 +907,7 @@ protected function parseTemplateTree($tree, $filter_id = null) . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n"; } - if (count($element['children'])) { + if (isset($element['children']) && count($element['children'])) { $this->parseTemplateTree($element['children'], $extendedObj); } } @@ -921,6 +921,8 @@ protected function parseTemplateTree($tree, $filter_id = null) public function export($filters = null) { $filters["service_register"] = $this->register; + $filters['service_id'] = isset($filters['service_id']) ? $filters['service_id'] : null; + $elements = $this->object->getList( "*", -1, @@ -967,7 +969,7 @@ public function export($filters = null) // contacts $contactRel = new \Centreon_Object_Relation_Contact_Service($this->dependencyInjector); $filters_contactRel = array("service_register" => $this->register); - if (!is_null($filters['service_id'])) { + if (isset($filters['service_id']) && !is_null($filters['service_id'])) { $filters_contactRel['service_id'] = $filters['service_id']; } $elements = $contactRel->getMergedParameters( @@ -981,7 +983,11 @@ public function export($filters = null) "AND" ); foreach ($elements as $element) { - $this->api->export_filter('CONTACT', $element['contact_id'], $element['contact_name']); + $exportContactId = isset($element['contact_id']) ? $element['contact_id'] : null; + $exportContactName = isset($element['contact_name']) ? $element['contact_name'] : null; + + $this->api->export_filter('CONTACT', $exportContactId, $exportContactName); + echo $this->action . $this->delim . "addcontact" . $this->delim . $element['service_description'] . $this->delim @@ -996,7 +1002,7 @@ public function export($filters = null) 0, null, null, - array('svc_svc_id' => $element[$this->object->getPrimaryKey()]), + array('svc_svc_id' => isset($element[$this->object->getPrimaryKey()]) ? $element[$this->object->getPrimaryKey()] : null), "AND" ); foreach ($macros as $macro) { From 6e546c9d955870508632051e7393d18ddfaa1021 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Mon, 28 May 2018 18:01:03 +0300 Subject: [PATCH 2/3] fix(global): PHP 7 compatability fix PHP notices related to undefined index and fix CentreonObject::add compatibility with child objects Resolves CP7M-51 --- www/class/centreon-clapi/centreonObject.class.php | 6 ++++-- www/class/centreon-clapi/centreonServiceTemplate.class.php | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/www/class/centreon-clapi/centreonObject.class.php b/www/class/centreon-clapi/centreonObject.class.php index 2cf2d845e08..f9f1032a311 100644 --- a/www/class/centreon-clapi/centreonObject.class.php +++ b/www/class/centreon-clapi/centreonObject.class.php @@ -267,9 +267,10 @@ protected function checkParameters() /** * Add Action * + * @param mixed $parameters * @return int */ - public function add() + public function add($parameters = NULL) { $id = $this->object->insert($this->params); $this->addAuditLog( @@ -347,9 +348,10 @@ public function setparam($objectId, $params = array()) * Shows list * * @param array $params + * @param array $filters * @return void */ - public function show($params = array(), $filters = array()) + public function show(array $params = NULL, array $filters = NULL) { echo str_replace("_", " ", implode($this->delim, $params)) . "\n"; $elements = $this->object->getList($params, -1, 0, null, null, $filters); diff --git a/www/class/centreon-clapi/centreonServiceTemplate.class.php b/www/class/centreon-clapi/centreonServiceTemplate.class.php index 7a92e11617c..f5b71851e60 100644 --- a/www/class/centreon-clapi/centreonServiceTemplate.class.php +++ b/www/class/centreon-clapi/centreonServiceTemplate.class.php @@ -505,6 +505,9 @@ public function setmacro($parameters) if (count($params) < 3) { throw new CentreonClapiException(self::MISSINGPARAMETER); } + + $params[3] = isset($params[3]) ? $params[3] : null; + $elements = $this->object->getList( "service_id", -1, From bfb354343c5d88404e2ed0c716e3177a960acd57 Mon Sep 17 00:00:00 2001 From: Valentin Hristov Date: Tue, 29 May 2018 10:22:29 +0300 Subject: [PATCH 3/3] set NULL in lower case --- www/class/centreon-clapi/centreonObject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/class/centreon-clapi/centreonObject.class.php b/www/class/centreon-clapi/centreonObject.class.php index f9f1032a311..a130b7ec1aa 100644 --- a/www/class/centreon-clapi/centreonObject.class.php +++ b/www/class/centreon-clapi/centreonObject.class.php @@ -351,7 +351,7 @@ public function setparam($objectId, $params = array()) * @param array $filters * @return void */ - public function show(array $params = NULL, array $filters = NULL) + public function show(array $params = null, array $filters = null) { echo str_replace("_", " ", implode($this->delim, $params)) . "\n"; $elements = $this->object->getList($params, -1, 0, null, null, $filters);