Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Cp7 m7 fix code errors and warnings #6275

Merged
merged 7 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion www/class/centreon-clapi/centreon.Config.Poller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ public function cfgMove($variables)
$msg_copy = "";
foreach (glob($this->nagiosCFGPath . '/' . $poller_id . "/*.cfg") as $filename) {
$bool = @copy($filename, $Nagioscfg["cfg_dir"] . "/" . basename($filename));
$filename = array_pop(explode("/", $filename));
$result = explode("/", $filename);
$filename = array_pop($result);
if (!$bool) {
$msg_copy .= $this->display_copying_file($filename, " - " . _("movement") . " KO");
$return = 1;
Expand Down
7 changes: 4 additions & 3 deletions www/class/centreonService.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,15 @@ public static function getDefaultValuesParameters($field)
*/
public function getObjectForSelect2($values = array(), $options = array(), $register = '1')
{

$hostgroup = false;
$hostIdList = array();
$serviceIdList = array();
$values = is_array($values) ? $values : [];

if (isset($options['hostgroup']) && $options['hostgroup'] == true) {
$hostgroup = true;
}

$hostIdList = array();
$serviceIdList = array();
foreach ($values as $value) {
if (strpos($value, '-')) {
$tmpValue = explode('-', $value);
Expand Down
8 changes: 5 additions & 3 deletions www/class/centreonServicetemplates.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ public static function getDefaultValuesParameters($field)
}

/**
* @param array $values
* @param array $options
* @param array $values
* @param array $options
* @param string $register
*
* @return array|type
*/
public function getObjectForSelect2($values = array(), $options = array())
public function getObjectForSelect2($values = array(), $options = array(), $register = '1')
{
$serviceList = array();
if (isset($options['withHosttemplate']) && $options['withHosttemplate'] === true) {
Expand Down
20 changes: 11 additions & 9 deletions www/class/centreonUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function objectIntoArray($arrObjData, $arrSkipIndices = array())
* @param bool $or
* @return string
*/
public function conditionBuilder($query, $condition, $or = false)
public static function conditionBuilder($query, $condition, $or = false)
{
if (preg_match('/ WHERE /', $query)) {
if ($or === true) {
Expand Down Expand Up @@ -168,7 +168,7 @@ public function getDateTimeTimestamp($datetime)
* @param string $str
* @return string;
*/
public function operandToMysqlFormat($str)
public static function operandToMysqlFormat($str)
{
$result = "";
switch ($str) {
Expand Down Expand Up @@ -210,18 +210,20 @@ public function operandToMysqlFormat($str)
* @param string $key
* @return array
*/
public function mergeWithInitialValues($form, $key)
public static function mergeWithInitialValues($form, $key)
{
$init = array();
$initForm = $form->getElement('initialValues');
$c = get_class($initForm);
if (!is_null($form) && $c != "HTML_QuickForm_Error") {
try {
$initForm = $form->getElement('initialValues');
$initialValues = unserialize($initForm->getValue());
if (count($initialValues) && isset($initialValues[$key])) {
if (!empty($initialValues) && isset($initialValues[$key])) {
$init = $initialValues[$key];
}
$result = array_merge((array)$form->getSubmitValue($key), $init);
} catch (HTML_QuickForm_Error $e) {
$result = [];
}
return array_merge((array)$form->getSubmitValue($key), $init);
return $result;
}

/**
Expand All @@ -233,7 +235,7 @@ public function mergeWithInitialValues($form, $key)
* otherwise values will be used
* @return string
*/
public function toStringWithQuotes($arr = array(), $transformKey = true)
public static function toStringWithQuotes($arr = array(), $transformKey = true)
{
$string = "";
$first = true;
Expand Down
6 changes: 3 additions & 3 deletions www/class/config-generate/abstract/service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function getMacros(&$service)
return 1;
}

$service['macros'] = &Macro::getInstance($this->dependencyInjector)
$service['macros'] = Macro::getInstance($this->dependencyInjector)
->getServiceMacroByServiceId($service['service_id']);
return 0;
}
Expand All @@ -176,7 +176,7 @@ protected function getContacts(&$service)
$service['contacts'] = "";
} else {
$contact = Contact::getInstance($this->dependencyInjector);
$service['contacts_cache'] = &$contact->getContactForService($service['service_id']);
$service['contacts_cache'] = $contact->getContactForService($service['service_id']);
$contact_result = '';
$contact_result_append = '';
foreach ($service['contacts_cache'] as $contact_id) {
Expand Down Expand Up @@ -207,7 +207,7 @@ protected function getContactGroups(&$service)
$service['contact_groups'] = "";
} else {
$cg = Contactgroup::getInstance($this->dependencyInjector);
$service['contact_groups_cache'] = &$cg->getCgForService($service['service_id']);
$service['contact_groups_cache'] = $cg->getCgForService($service['service_id']);
$cg_result = '';
$cg_result_append = '';
foreach ($service['contact_groups_cache'] as $cg_id) {
Expand Down
2 changes: 1 addition & 1 deletion www/class/config-generate/broker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private function generate($poller_id, $localhost)
// We search the BlockId
$blockId = 0;
for ($i = count($value); $i > 0; $i--) {
if ($value[$i]['config_key'] == 'blockId') {
if (isset($value[$i]['config_key']) && $value[$i]['config_key'] == 'blockId') {
$blockId = $value[$i]['config_value'];
break;
}
Expand Down
3 changes: 2 additions & 1 deletion www/class/config-generate/engine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ private function generate($poller_id)
$this->stmt_engine->bindParam(':poller_id', $poller_id, PDO::PARAM_INT);
$this->stmt_engine->execute();

$this->engine = array_pop($this->stmt_engine->fetchAll(PDO::FETCH_ASSOC));
$result = $this->stmt_engine->fetchAll(PDO::FETCH_ASSOC);
$this->engine = array_pop($result);
if (is_null($this->engine)) {
throw new Exception("Cannot get engine configuration for poller id (maybe not activate) '" .
$poller_id . "'");
Expand Down
10 changes: 6 additions & 4 deletions www/class/config-generate/generate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function generateIndexData($localhost = 0)
{
$service_instance = Service::getInstance($this->dependencyInjector);
$host_instance = Host::getInstance($this->dependencyInjector);
$services = &$service_instance->getGeneratedServices();
$services = $service_instance->getGeneratedServices();

try {
$query = "INSERT INTO index_data (host_id, service_id, host_name, service_description) VALUES " .
Expand All @@ -107,7 +107,7 @@ private function generateIndexData($localhost = 0)

# Meta services
if ($localhost == 1) {
$meta_services = &MetaService::getInstance($this->dependencyInjector)->getMetaServices();
$meta_services = MetaService::getInstance($this->dependencyInjector)->getMetaServices();
$host_id = MetaHost::getInstance($this->dependencyInjector)->getHostIdByHostName('_Module_Meta');
foreach ($meta_services as $meta_id => $meta_service) {
$stmt->bindValue(':host_name', '_Module_Meta', PDO::PARAM_STR);
Expand All @@ -133,7 +133,8 @@ private function getPollerFromId($poller_id)
$stmt = $this->backend_instance->db->prepare($query);
$stmt->bindParam(':poller_id', $poller_id, PDO::PARAM_INT);
$stmt->execute();
$this->current_poller = array_pop($stmt->fetchAll(PDO::FETCH_ASSOC));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->current_poller = array_pop($result);
if (is_null($this->current_poller)) {
throw new Exception("Cannot find poller id '" . $poller_id . "'");
}
Expand All @@ -146,7 +147,8 @@ private function getPollerFromName($poller_name)
$stmt = $this->backend_instance->db->prepare($query);
$stmt->bindParam(':poller_name', $poller_name, PDO::PARAM_STR);
$stmt->execute();
$this->current_poller = array_pop($stmt->fetchAll(PDO::FETCH_ASSOC));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->current_poller = array_pop($resutl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resutl -> result

if (is_null($this->current_poller)) {
throw new Exception("Cannot find poller name '" . $poller_name . "'");
}
Expand Down
3 changes: 2 additions & 1 deletion www/class/config-generate/meta_host.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public function getHostIdByHostName($host_name)
");
$stmt->bindParam(':host_name', $host_name, PDO::PARAM_STR);
$stmt->execute();
return array_pop($stmt->fetchAll(PDO::FETCH_COLUMN));
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
return array_pop($result);
}

public function generateObject($host_id)
Expand Down
7 changes: 5 additions & 2 deletions www/class/config-generate/service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function use_cache()
private function getServiceGroups($service_id, $host_id, $host_name)
{
$servicegroup = Servicegroup::getInstance($this->dependencyInjector);
$this->service_cache[$service_id]['sg'] = &$servicegroup->getServiceGroupsForService($host_id, $service_id);
$this->service_cache[$service_id]['sg'] = $servicegroup->getServiceGroupsForService($host_id, $service_id);
foreach ($this->service_cache[$service_id]['sg'] as &$value) {
if (is_null($value['host_host_id']) || $host_id == $value['host_host_id']) {
$servicegroup->addServiceInSg(
Expand Down Expand Up @@ -167,7 +167,10 @@ private function browseContactsInStpl($service_id)
: null;
}

$this->service_cache[$service_id]['has_tpl_contacts'] = $services_tpl[$service_tpl_top_id]['has_tpl_contacts'];
$this->service_cache[$service_id]['has_tpl_contacts'] = isset($services_tpl[$service_tpl_top_id]['has_tpl_contacts']) ?
$services_tpl[$service_tpl_top_id]['has_tpl_contacts'] :
null
;
$this->service_cache[$service_id]['has_tpl_contact_groups'] =
$services_tpl[$service_tpl_top_id]['has_tpl_contact_groups'];
}
Expand Down
2 changes: 1 addition & 1 deletion www/class/config-generate/servicetemplate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function getServiceGroups($service_id)
{
$host = Host::getInstance($this->dependencyInjector);
$servicegroup = Servicegroup::getInstance($this->dependencyInjector);
$this->service_cache[$service_id]['sg'] = &$servicegroup->getServiceGroupsForStpl($service_id);
$this->service_cache[$service_id]['sg'] = $servicegroup->getServiceGroupsForStpl($service_id);
foreach ($this->service_cache[$service_id]['sg'] as &$sg) {
if ($host->isHostTemplate($this->current_host_id, $sg['host_host_id'])) {
$servicegroup->addServiceInSg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
'conditions' => array('ns_activate' => 1)));

/* Sort the list of poller server */
$pollersId = explode(',', $_GET['poller']);
$pollersId = isset($_GET['poller']) ? explode(',', $_GET['poller']) : [];

foreach ($tab_nagios_server as $key => $name) {
if (in_array($key, $pollersId)) {
$tab_nagios_server[$key] = $name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function return_plugin($rep)
&& substr($filename, -1)!= "~"
&& substr($filename, -1) != "#"
) {
$key = substr($rep."/".$filename, strlen($oreon->optGen["cengine_path_connectors"]));
if ( isset($oreon) ) {
$key = substr($rep."/".$filename, strlen($oreon->optGen["cengine_path_connectors"]));
} else {
$key = substr($rep."/".$filename, 0);
}

$availableConnectors[$key] = $key;
}
}
Expand Down
17 changes: 15 additions & 2 deletions www/include/configuration/configObject/contact/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,13 @@ function updateContactHostCommands($contact_id = null, $ret = array())
$ret = $form->getSubmitValue("contact_hostNotifCmds");
}

for ($i = 0; $i < count($ret); $i++) {
if (is_array($ret) || $ret instanceof Countable) {
$resultsCount = count($ret);
} else {
$resultsCount = 0;
}

for ($i = 0; $i < $resultsCount; $i++) {
$rq = "INSERT INTO contact_hostcommands_relation ";
$rq .= "(contact_contact_id, command_command_id) ";
$rq .= "VALUES ";
Expand Down Expand Up @@ -946,7 +952,14 @@ function updateContactServiceCommands($contact_id = null, $ret = array())
} else {
$ret = $form->getSubmitValue("contact_svNotifCmds");
}
for ($i = 0; $i < count($ret); $i++) {

if (is_array($ret) || $ret instanceof Countable) {
$resultsCount = count($ret);
} else {
$resultsCount = 0;
}

for ($i = 0; $i < $resultsCount; $i++) {
$rq = "INSERT INTO contact_servicecommands_relation ";
$rq .= "(contact_contact_id, command_command_id) ";
$rq .= "VALUES ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ function myReplace()
/*
* Apply a template definition
*/
$contactAuthType = isset($cct['contact_auth_type']) ? $cct['contact_auth_type'] : null;
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl, true);
$renderer->setRequiredTemplate('{$label}&nbsp;<font color="red" size="1">*</font>');
$renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
Expand All @@ -754,7 +755,7 @@ function myReplace()
if ($centreon->optGen['ldap_auth_enable']) {
$tpl->assign('ldap', $centreon->optGen['ldap_auth_enable']);
}
$tpl->assign('auth_type', $cct['contact_auth_type']);
$tpl->assign('auth_type', $contactAuthType);
$tpl->display("formContact.ihtml");
}
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
$contact['contact_id'] . "]' />";

$contact_type = 0;
if ($contact["contact_register"]) {
if ($contact["contact_admin"] == 1) {
if (isset($contact['contact_register']) && $contact['contact_register']) {
if ($contact['contact_admin'] == 1) {
$contact_type = 1;
} else {
$contact_type = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require_once _CENTREON_PATH_ . 'www/class/centreonContactgroup.class.php';

$hostObj = new CentreonHost($pearDB);
$hTpls = isset($hTpls) ? $hTpls : [];

#
## Database retrieve information for Host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

include_once("./class/centreonUtils.class.php");

$hostgroupsFilter = isset($hostgroupsFilter) ? $hostgroupsFilter : null;
$statusHostFilter = isset($statusHostFilter) ? $statusHostFilter : null;

/*
* Object init
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@

$mediaObj = new CentreonMedia($pearDB);

if (isset($_POST["hostgroups"])) {
$searchHG = $_POST["hostgroups"];
if (isset($_POST['hostgroups'])) {
$searchHG = $_POST['hostgroups'];
$centreon->svc_hostgroup_search = $searchHG;
if ($_POST["searchH"] != "") {

if (isset($_POST['searchH']) && $_POST['searchH'] != '') {
$search_type_host = 1;
$centreon->search_type_host = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function myDecodeSvTP($arg)
* Preset values of macros
*/
$cdata = CentreonData::getInstance();
$aMacros = isset($aMacros) ? $aMacros : [];

$cdata->addJsData('clone-values-macro', htmlspecialchars(
json_encode($aMacros),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@
$k++;
}

var_dump($k);

$DBRESULT->closeCursor();

/*
Expand Down
1 change: 1 addition & 0 deletions www/include/configuration/configResources/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function testExistence($name = null, $instanceId = null)
if (isset($form)) {
$id = $form->getSubmitValue('resource_id');
$instances = $form->getSubmitValue('instance_id');
$instances = (!empty($instances)) ?: [];
} elseif (!is_null($instanceId) && $instanceId) {
$instances = array($instanceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[" .
$resource['resource_id'] . "]' />";
$elemArr[$i] = array(
"order" => $tabResources[1],
"order" => isset($tabResources[1]) ? $tabResources[1] : null,
"MenuClass" => "list_" . $style,
"RowMenu_select" => $selectedElements->toHtml(),
"RowMenu_name" => CentreonUtils::escapeSecure($resource["resource_name"]),
Expand Down
1 change: 1 addition & 0 deletions www/include/configuration/configServers/formServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
require_once _CENTREON_PATH_ . "www/class/centreon-config/centreonMainCfg.class.php";

$objMain = new CentreonMainCfg();
$monitoring_engines = [];

if (!$centreon->user->admin && $server_id && count($serverResult)) {
if (!isset($serverResult[$server_id])) {
Expand Down
4 changes: 2 additions & 2 deletions www/include/configuration/configServers/listServers.ihtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
{section name=elem loop=$elemArr}
<tr class={$elemArr[elem].MenuClass}>
<td class="ListColPicker">{$elemArr[elem].RowMenu_select}</td>
<td class="ListColLeft">{if $mode_access == w}<a href="{$elemArr[elem].RowMenu_link}">{/if}{$elemArr[elem].RowMenu_name}{if $mode_access == w}</a>{/if}</td>
<td class="ListColCenter">{if $mode_access == w}<a href="{$elemArr[elem].RowMenu_link}">{/if}{$elemArr[elem].RowMenu_ip_address}{if $mode_access == w}</a>{/if}</td>
<td class="ListColLeft">{if $mode_access == 'w'}<a href="{$elemArr[elem].RowMenu_link}">{/if}{$elemArr[elem].RowMenu_name}{if $mode_access == 'w'}</a>{/if}</td>
<td class="ListColCenter">{if $mode_access == 'w'}<a href="{$elemArr[elem].RowMenu_link}">{/if}{$elemArr[elem].RowMenu_ip_address}{if $mode_access == 'w'}</a>{/if}</td>
<td class="ListColCenter">{$elemArr[elem].RowMenu_localisation}</td>
<td class="ListColCenter">
<span class="badge {if $elemArr[elem].RowMenu_is_runningFlag}service_ok{else}service_critical{/if}">
Expand Down
Loading