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

Commit

Permalink
MON-11557-broker-conf-form-issues (#10401)
Browse files Browse the repository at this point in the history
* fix(conf/broker) fix empty input forms pb

* Update www/class/centreonConfigCentreonBroker.php

Co-authored-by: Laurent Calvet <lcalvet@centreon.com>
  • Loading branch information
a-launois and callapa committed Nov 22, 2021
1 parent 59b3352 commit abfc5e8
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions www/class/centreonConfigCentreonBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class CentreonConfigCentreonBroker
*/
public $nbSubGroup = 1;

/**
*
* @var array
*/
public $arrayMultiple = [];

/**
*
* @var \CentreonDB
Expand All @@ -76,31 +82,31 @@ class CentreonConfigCentreonBroker

/**
*
* @var type
* @var array<int|string,mixed>|null
*/
private $tagsCache = null;

/**
*
* @var type
* @var array<int|string,mixed>|null
*/
private $logsCache = null;

/**
*
* @var type
* @var array<int|string,string>|null
*/
private $logsLevelCache = null;

/**
*
* @var type
* @var array<int,string>|null
*/
private $typesCache = null;

/**
*
* @var type
* @var array<int,string>|null
*/
private $typesNameCache = null;

Expand Down Expand Up @@ -185,7 +191,7 @@ public function __sleep()
*
* @param CentreonDB $db The connection to centreon database
*/
public function setDb($db)
public function setDb($db): void
{
$this->db = $db;
}
Expand Down Expand Up @@ -366,12 +372,10 @@ public function getListConfigBlock($tagId)
return $this->blockCache[$tagId];
}

public $arrayMultiple;

/**
* Create the HTML_QuickForm object with element for a block
*
* @param int $blockId The block id ('tag_id'_'type_id')
* @param string $blockId The block id ('tag_id'_'type_id')
* @param int $page The centreon page id
* @param int $formId The form post
* @param int $config_id
Expand Down Expand Up @@ -581,7 +585,7 @@ public function quickFormById($blockId, $page, $formId = 1, $config_id = 0)
/**
* Generate Cdata tag
*/
public function generateCdata()
public function generateCdata(): void
{
$cdata = CentreonData::getInstance();
if (isset($this->arrayMultiple)) {
Expand Down Expand Up @@ -651,8 +655,8 @@ public function getBlockInfos($typeId)

/**
* Return a cb type id for the shortname given
* @param type $typeName
* @return boolean
* @param string $typeName
* @return int|null
*/
public function getTypeId($typeName)
{
Expand Down Expand Up @@ -756,6 +760,7 @@ public function insertConfig($values)
return false;
}
$this->updateCentreonBrokerInfos($id, $values);
return true;
}

/**
Expand Down Expand Up @@ -827,6 +832,7 @@ public function updateConfig(int $id, array $values)
return false;
}
$this->updateCentreonBrokerInfos($id, $values);
return true;
}

/**
Expand All @@ -840,7 +846,7 @@ public function updateCentreonBrokerInfos($id, $values)
{
// exclude multiple parameters load with broker js hook
$keepLuaParameters = false;
if ($values['output'] !== null) {
if (isset($values['output'])) {
foreach ($values['output'] as $key => $output) {
if ($output['type'] === 'lua') {
if ($this->removeUnindexedLuaParameters($values, $key)) {
Expand All @@ -849,12 +855,12 @@ public function updateCentreonBrokerInfos($id, $values)
$this->removeEmptyLuaParameters($values, $key);
}
}
// Clean the informations for this id
$query = 'DELETE FROM cfg_centreonbroker_info WHERE config_id = '
. (int) $id
. ($keepLuaParameters ? ' AND config_key NOT LIKE "lua\_parameter\_%"' : '');
$this->db->query($query);
}
// Clean the informations for this id
$query = 'DELETE FROM cfg_centreonbroker_info WHERE config_id = '
. (int) $id
. ($keepLuaParameters ? ' AND config_key NOT LIKE "lua\_parameter\_%"' : '');
$this->db->query($query);

$groups_infos = array();
$groups_infos_multiple = array();
Expand Down Expand Up @@ -890,7 +896,7 @@ public function updateCentreonBrokerInfos($id, $values)
foreach ($groups as $gid => $infos) {
if (isset($infos['blockId'])) {
list($tagId, $typeId) = explode('_', $infos['blockId']);
$fieldtype = $this->getFieldtypes($typeId);
$fieldtype = $this->getFieldtypes((int) $typeId);
foreach ($infos as $fieldname => $fieldvalue) {
$lvl = 0;
$grp_id = null;
Expand Down Expand Up @@ -1035,10 +1041,10 @@ private function removeEmptyLuaParameters(array &$values, int $key): void
/**
* Get the list of forms for a config_id
*
* @param $config_id int $config_id The id of config
* @param $tag string $tag The tag name
* @param $page int $page The page topology
* @param $tpl Smarty $tpl The template Smarty
* @param int $config_id The id of config
* @param string $tag The tag name
* @param int $page The page topology
* @param Smarty $tpl The template Smarty
* @return array
* @throws HTML_QuickForm_Error
*/
Expand Down Expand Up @@ -1199,7 +1205,7 @@ public function getHelps($config_id, $tag)
while ($row = $res->fetchRow()) {
list($tagId, $typeId) = explode('_', $row['config_value']);
$pos = $row['config_group_id'];
$fields = $this->getBlockInfos($typeId);
$fields = $this->getBlockInfos((int) $typeId);
$help = array();
$help[] = array('name' => $tag . '[' . $pos . '][name]', 'desc' => _('The name of block configuration'));
$help[] = array('name' => $tag . '[' . $pos . '][type]', 'desc' => _('The type of block configuration'));
Expand Down Expand Up @@ -1408,7 +1414,7 @@ public function getInfoDb($string)
*
* @param string $rpn The rpn operation
* @param int $val The value for apply
* @return The value with rpn apply or the value is errors
* @return mixed The value with rpn apply or the value is errors
*/
private function rpnCalc($rpn, $val)
{
Expand Down

0 comments on commit abfc5e8

Please sign in to comment.