php8 incompatibility fixes

This commit is contained in:
fbsanchez 2022-02-07 13:35:00 +01:00
parent 8b09c49871
commit aa2b08f516
4 changed files with 41 additions and 19 deletions

View File

@ -1713,16 +1713,12 @@ function agents_get_name($id_agent, $case='none')
case 'upper': case 'upper':
return mb_strtoupper($agent, 'UTF-8'); return mb_strtoupper($agent, 'UTF-8');
break;
case 'lower': case 'lower':
return mb_strtolower($agent, 'UTF-8'); return mb_strtolower($agent, 'UTF-8');
break;
case 'none': case 'none':
default: default:
return ($agent); return ($agent);
break;
} }
} }
@ -1809,23 +1805,37 @@ function agents_get_alias_array($array_ids)
/** /**
* Get alias of an agent (cached function). * Get alias of an agent (cached function).
* *
* @param integer $id_agent Agent id. * @param integer|array $id_agent Agent id or array or box, also a boat.
* @param string $case Case (upper, lower, none). * @param string $case Case (upper, lower, none).
* *
* @return string Alias of the given agent. * @return string Alias of the given agent.
*/ */
function agents_get_alias($id_agent, $case='none') function agents_get_alias(int|array $id_agent, string $case='none')
{ {
global $config;
// Prepare cache. // Prepare cache.
static $cache = []; static $cache = [];
if (empty($case)) { if (empty($case) === true) {
$case = 'none'; $case = 'none';
} }
$agent_alias = '';
if (is_array($id_agent) === true) {
foreach ($id_agent as $agg) {
$agent_alias .= agents_get_alias($agg, $case);
}
return $agent_alias;
}
if (isset($cache[$case]) === false) {
$cache[$case] = [];
}
// Check cache. // Check cache.
if (!is_metaconsole()) { if (is_metaconsole() === false) {
if (isset($cache[$case][$id_agent])) { if (is_numeric($id_agent) === true && isset($cache[$case]) === true
&& isset($cache[$case][$id_agent]) === true
) {
return $cache[$case][$id_agent]; return $cache[$case][$id_agent];
} }
} }
@ -1851,7 +1861,7 @@ function agents_get_alias($id_agent, $case='none')
break; break;
} }
if (!is_metaconsole()) { if (is_metaconsole() === false) {
$cache[$case][$id_agent] = $alias; $cache[$case][$id_agent] = $alias;
} }

View File

@ -3003,7 +3003,8 @@ function events_get_group_events_steps(
* @param boolean $id_server Id_server. * @param boolean $id_server Id_server.
* @param boolean $filter_event_filter_exclude Filter_event_filter_exclude. * @param boolean $filter_event_filter_exclude Filter_event_filter_exclude.
* *
* @return array An array with all the events happened. * @return array|false An array with all the events happened. False if something
* failed.
*/ */
function events_get_agent( function events_get_agent(
$id_agent, $id_agent,

View File

@ -1468,7 +1468,15 @@ function graphic_combined_module(
'module_description' => $module_description, 'module_description' => $module_description,
]; ];
if ($source['label'] != '') { if (is_array($source['label']) === true) {
$lab = '';
foreach ($source['label'] as $label) {
$lab .= reporting_label_macro(
$items_label,
$label
);
}
} else if ($source['label'] != '') {
$lab = reporting_label_macro( $lab = reporting_label_macro(
$items_label, $items_label,
$source['label'] $source['label']

View File

@ -2343,19 +2343,19 @@ function reporting_agents_inventory($report, $content)
$search_sql .= ' AND id_os IN ('.implode(',', $es_os_filter).')'; $search_sql .= ' AND id_os IN ('.implode(',', $es_os_filter).')';
} }
if ($es_agent_version_filter != '') { if (empty($es_agent_version_filter) === false) {
$search_sql .= ' AND tagente.agent_version LIKE "%'.$es_agent_version_filter.'%"'; $search_sql .= ' AND tagente.agent_version LIKE "%'.$es_agent_version_filter.'%"';
} }
if ($es_agent_module_search_filter != '') { if (empty($es_agent_module_search_filter) === false) {
$search_sql .= ' AND tam.nombre LIKE "%'.$es_agent_module_search_filter.'%"'; $search_sql .= ' AND tam.nombre LIKE "%'.$es_agent_module_search_filter.'%"';
} }
if ($es_agent_group_filter != 0) { if (empty($es_agent_group_filter) === false) {
$search_sql .= ' AND (tagente.id_grupo = '.$es_agent_group_filter.' OR tasg.id_group = '.$es_agent_group_filter.')'; $search_sql .= ' AND (tagente.id_grupo = '.$es_agent_group_filter.' OR tasg.id_group = '.$es_agent_group_filter.')';
} }
if ($es_agent_remote_conf != 0) { if (empty($es_agent_remote_conf) === false) {
$search_sql .= ' AND tagente.remote = '.$es_agent_remote_conf; $search_sql .= ' AND tagente.remote = '.$es_agent_remote_conf;
} }
@ -9925,6 +9925,9 @@ function reporting_get_module_detailed_event(
$id_server, $id_server,
$filter_event_filter_exclude $filter_event_filter_exclude
); );
if ($event['data'] === false) {
$event['data'] = [];
}
// total_events // total_events
if (isset($event['data'])) { if (isset($event['data'])) {
@ -13785,7 +13788,7 @@ function reporting_get_agentmodule_sla_working_timestamp($period, $date_end, $wt
* *
* @return string * @return string
*/ */
function reporting_label_macro($item, $label) function reporting_label_macro($item, string $label)
{ {
if (preg_match('/_agent_/', $label)) { if (preg_match('/_agent_/', $label)) {
$label = str_replace( $label = str_replace(