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

Commit

Permalink
Cp7 m7 fix code errors and warnings (#6282)
Browse files Browse the repository at this point in the history
* fix(global): remove warnings and undefined variables

* refactor(core): rework post-upgrade errors

Refactor code not compliant with php7.2

Regarding: CP7M-7

* fix(global): remove small warnings and errors

* refactor(core): call non-static method

in widgets as host-monitoring calls methods CentreonUtils::conditionBuilder and CentreonUtils::operandToMysqlFormat as static but they are non-static

Resolves CP7M-7

* fix(global): remove small warnings and errors

* refactor(core): fix warnings from tests

fix issues as "Only variables should be assigned by reference", "Undefined index", "Methods with the same name as their class will not be constructors in a future version of PHP" and etc.

Resolves CP7M-7

* fix(global): use quickform and smarty from composer

* fix(global): PHP warnings, notifications and mergeWithInitialValues to return correct result

fix CentreonUtils::mergeWithInitialValues to return result from submitted data
fix PHP warinings and notifications from Host template UI
fix CentreonHosttemplates::getObjectForSelect2 attributes to be the same as the parent method

Resolves CP7M-7

* refactor(base) Fix errors found after running acceptance tests

Fix various problems caused by Smarty and Quickform, detected by acceptance tests.

Regarding CP7M7

* fix(config): fix variable name (#6276)

Fix incorrectly pushed variable name
  • Loading branch information
v-radev authored May 16, 2018
1 parent bb6f78c commit c04db0f
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 19 deletions.
9 changes: 4 additions & 5 deletions www/api/class/centreon_configuration_broker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@

require_once dirname(__FILE__) . "/centreon_configuration_objects.class.php";

require_once __DIR__ . "/../../../GPL_LIB/Smarty/libs/Smarty.class.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm/advmultiselect.php";
require_once __DIR__ . "/../../lib/HTML/QuickForm/Renderer/ArraySmarty.php";

class CentreonConfigurationBroker extends CentreonConfigurationObjects
{
/**
Expand Down Expand Up @@ -90,11 +85,15 @@ public function getBlock()
* Smarty template Init
*/
$libDir = __DIR__ . "/../../../GPL_LIB";
$smartyDir = __DIR__ . '/../../../vendor/smarty/smarty/';
require_once $smartyDir . 'libs/Smarty.class.php';
$tpl = new \Smarty();
$tpl->compile_dir = $libDir . '/SmartyCache/compile';
$tpl->config_dir = $libDir . '/SmartyCache/config';
$tpl->cache_dir = $libDir . '/SmartyCache/cache';
$tpl->template_dir = _CENTREON_PATH_ . '/www/include/configuration/configCentreonBroker/';
$tpl->plugins_dir[] = $libDir . '/smarty-plugins';

$tpl->caching = 0;
$tpl->compile_check = true;
$tpl->force_compile = true;
Expand Down
4 changes: 2 additions & 2 deletions www/class/centreonConfigCentreonBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function quickFormById($blockId, $page, $formId = 1, $config_id = 0)
$tag = $this->getTagName($tagId);
$this->nbSubGroup = 1;

$qf = new HTML_QuickForm('form_' . $formId, 'post', '?p=' . $page);
$qf = new HTML_QuickFormCustom('form_' . $formId, 'post', '?p=' . $page);

$qf->addElement(
'text',
Expand Down Expand Up @@ -391,7 +391,7 @@ public function quickFormById($blockId, $page, $formId = 1, $config_id = 0)
}

foreach ($this->getListValues($field['id']) as $key => $value) {
$tmpRadio[] = HTML_QuickForm::createElement(
$tmpRadio[] = $qf->createElement(
'radio',
$field['fieldname'],
null,
Expand Down
4 changes: 3 additions & 1 deletion www/class/centreonHosttemplates.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ class CentreonHosttemplates extends CentreonHost
/**
*
* @param array $values
* @param array $options
* @param string $register
* @return array
*/
public function getObjectForSelect2($values = array(), $options = array())
public function getObjectForSelect2($values = array(), $options = array(), $register = '1')
{
return parent::getObjectForSelect2($values, $options, '0');
}
Expand Down
2 changes: 1 addition & 1 deletion www/class/centreonUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function mergeWithInitialValues($form, $key)
}
$result = array_merge((array)$form->getSubmitValue($key), $init);
} catch (HTML_QuickForm_Error $e) {
$result = [];
$result = (array) $form->getSubmitValue($key);
}
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion www/include/common/common-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function initSmartyTplForPopup($path = null, $tpl = null, $subDir = null, $centr
$tpl->compile_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/compile";
$tpl->config_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/config";
$tpl->cache_dir = _CENTREON_PATH_ . "/GPL_LIB/SmartyCache/cache";

$tpl->plugins_dir[] = _CENTREON_PATH_ . "/GPL_LIB/smarty-plugins";
$tpl->caching = 0;
$tpl->compile_check = true;
$tpl->force_compile = true;
Expand Down
10 changes: 6 additions & 4 deletions www/include/configuration/configObject/command/minCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function myDecodeCommand($arg)
$attrsText = array("size" => "35");
$attrsTextarea = array("rows" => "9", "cols" => "80");

$form = new HTML_QuickForm('Form', 'post', "?p=" . $p);
$form = new HTML_QuickFormCustom('Form', 'post', "?p=" . $p);
$form->addElement('header', 'title', _("View command definition"));

/*
Expand All @@ -109,8 +109,8 @@ function myDecodeCommand($arg)
}


$cmdType[] = HTML_QuickForm::createElement('radio', 'command_type', null, _("Notification"), '1');
$cmdType[] = HTML_QuickForm::createElement('radio', 'command_type', null, _("Check"), '2');
$cmdType[] = $form->createElement('radio', 'command_type', null, _("Notification"), '1');
$cmdType[] = $form->createElement('radio', 'command_type', null, _("Check"), '2');

$v1 = $form->addGroup($cmdType, 'command_type', _("Command Type"), '  ');
$v1->freeze();
Expand All @@ -132,7 +132,9 @@ function myDecodeCommand($arg)
"command_type" => $cmd["command_type"]["command_type"]
));

$form->setDefaults(array("command_id1" => $cmd["command_id"]));
if (isset($cmd['command_id'])) {
$form->setDefaults(['command_id1' => $cmd['command_id']]);
}

/*
* Further informations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,9 @@ function myReplace()
$form->addRule('contact_email', _("Valid Email"), 'required');
$form->addRule('contact_oreon', _("Required Field"), 'required');
$form->addRule('contact_lang', _("Required Field"), 'required');
$form->addRule('contact_admin', _("Required Field"), 'required');
if ($centreon->user->admin) {
$form->addRule('contact_admin', _("Required Field"), 'required');
}
$form->addRule('contact_auth_type', _("Required Field"), 'required');

if (isset($ret["contact_enable_notifications"]["contact_enable_notifications"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
$form->addElement("button", "ldap_search_button", _("Search"), array("class" => "btc bt_success", "onClick" => $link));

$tab = array();
$tab[] = HTML_QuickForm::createElement('radio', 'action', null, _("List"), '1');
$tab[] = HTML_QuickForm::createElement('radio', 'action', null, _("Form"), '0');
$tab[] = $form->createElement('radio', 'action', null, _("List"), '1');
$tab[] = $form->createElement('radio', 'action', null, _("Form"), '0');
$form->addGroup($tab, 'action', _("Post Validation"), ' ');
$form->setDefaults(array('action' => '1'));

Expand Down
12 changes: 11 additions & 1 deletion www/include/configuration/configObject/service/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,11 @@ function updateServiceContactGroup($service_id = null, $ret = array())
}

$cg = new CentreonContactgroup($pearDB);

if (!$ret) {
return;
}

for ($i = 0; $i < count($ret); $i++) {
if (!is_numeric($ret[$i])) {
$res = $cg->insertLdapGroup($ret[$i]);
Expand Down Expand Up @@ -1700,7 +1705,7 @@ function updateServiceNotifs($service_id = null, $ret = array())
$rq .= "service_notification_options = ";
isset($ret) && $ret != null ? $rq .= "'" . implode(",", array_keys($ret)) . "' " : $rq .= "NULL ";
$rq .= "WHERE service_id = '" . $service_id . "'";
$DBRESULT =& $pearDB->query($rq);
$DBRESULT = $pearDB->query($rq);
}

// For massive change. incremental mode
Expand Down Expand Up @@ -2037,6 +2042,11 @@ function updateServiceTrap($service_id = null, $ret = array())
} else {
$ret = $form->getSubmitValue("service_traps");
}

if (!$ret) {
return;
}

for ($i = 0; $i < count($ret); $i++) {
$rq = "INSERT INTO traps_service_relation ";
$rq .= "(traps_id, service_id) ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ function updateServiceDependencyServiceParents($dep_id = null, $ret = array())
}
global $form;
global $pearDB;
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "DELETE FROM dependency_serviceParent_relation ";
$rq .= "WHERE dependency_dep_id = '" . $dep_id . "'";
$DBRESULT = $pearDB->query($rq);
Expand Down Expand Up @@ -352,6 +355,9 @@ function updateServiceDependencyServiceChilds($dep_id = null, $ret = array())
}
global $form;
global $pearDB;
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "DELETE FROM dependency_serviceChild_relation ";
$rq .= "WHERE dependency_dep_id = '" . $dep_id . "'";
$DBRESULT = $pearDB->query($rq);
Expand Down Expand Up @@ -382,6 +388,9 @@ function updateServiceDependencyHostChildren($dep_id = null, $ret = array())
}
global $form;
global $pearDB;
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "DELETE FROM dependency_hostChild_relation ";
$rq .= "WHERE dependency_dep_id = '" . $dep_id . "'";
$DBRESULT = $pearDB->query($rq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
$tplArr = array();
$tplStr = "";
$tplArr = getMyServiceTemplateModels($service["service_template_model_stm_id"]);
if (count($tplArr)) {

if ((is_array($tplArr) || $tplArr instanceof Countable) && count($tplArr)) {
foreach ($tplArr as $key => $value) {
$value = str_replace('#S#', "/", $value);
$value = str_replace('#BS#', "\\", $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ function updateServiceGroupDependencyServiceGroupParents($dep_id = null, $ret =
}
global $form;
global $pearDB;
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "DELETE FROM dependency_servicegroupParent_relation ";
$rq .= "WHERE dependency_dep_id = '" . $dep_id . "'";
$DBRESULT = $pearDB->query($rq);
Expand All @@ -329,6 +332,9 @@ function updateServiceGroupDependencyServiceGroupChilds($dep_id = null, $ret = a
}
global $form;
global $pearDB;
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "DELETE FROM dependency_servicegroupChild_relation ";
$rq .= "WHERE dependency_dep_id = '" . $dep_id . "'";
$DBRESULT = $pearDB->query($rq);
Expand Down

0 comments on commit c04db0f

Please sign in to comment.