Merge branch 'ent-8384-error-sql-ordenar-agent-id' into 'develop'

Added php8 function and solve issue with agent id sorting in events

Closes pandora_enterprise#8384

See merge request artica/pandorafms!4592
This commit is contained in:
Daniel Rodriguez 2021-12-23 12:19:24 +00:00
commit e0a925c2c1
2 changed files with 61 additions and 32 deletions

View File

@ -5966,3 +5966,24 @@ function send_test_email(
return $result;
}
if (function_exists('str_contains') === false) {
/**
* Checks if $needle is found in $haystack and returns a boolean value.
* For lower than PHP8 versions.
*
* @param string $haystack The string who can have the needle.
* @param string $needle The needle.
*
* @return boolean True if haystack contains the needle.
*/
function str_contains(string $haystack, string $needle)
{
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
}

View File

@ -261,11 +261,6 @@ if (is_ajax() === true) {
if ($get_events) {
try {
ob_start();
$order = get_datatable_order(true);
if (is_array($order) === true && $order['field'] === 'mini_severity') {
$order['field'] = 'te.criticity';
}
$fields = [
'te.id_evento',
@ -296,6 +291,20 @@ if (is_ajax() === true) {
'ta.direccion',
];
$order = get_datatable_order(true);
if (is_array($order) === true && $order['field'] === 'mini_severity') {
$order['field'] = 'te.criticity';
}
// Find the order field and set the table and field name.
foreach ($fields as $field) {
if (str_contains($field, $order['field']) === true) {
$order['field'] = $field;
break;
}
}
if (is_metaconsole() === false) {
$fields[] = 'am.nombre as module_name';
$fields[] = 'am.id_agente_modulo as id_agentmodule';
@ -345,7 +354,8 @@ if (is_ajax() === true) {
$tmp = (object) $item;
$tmp->meta = is_metaconsole();
if (is_metaconsole()) {
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
if ($tmp->meta === true) {
if ($tmp->server_name !== null) {
$tmp->data_server = metaconsole_get_servers($tmp->server_id);
$tmp->server_url_hash = metaconsole_get_servers_url_hash($tmp->data_server);
@ -371,7 +381,7 @@ if (is_ajax() === true) {
sprintf(
'SELECT criticity, timestamp FROM %s
WHERE id_evento = %s',
($tmp->meta) ? 'tmetaconsole_event' : 'tevento',
($tmp->meta === true) ? 'tmetaconsole_event' : 'tevento',
$tmp->max_id_evento
)
);
@ -538,7 +548,7 @@ if (is_array($tag_without) === false) {
}
foreach ($tags as $id_tag => $tag) {
foreach ((array) $tags as $id_tag => $tag) {
if (is_array($tag_with) === true
&& ((array_search($id_tag, $tag_with) === false) || (array_search($id_tag, $tag_with) === null))
) {
@ -2415,7 +2425,6 @@ function reorder_tags_inputs() {
});
$("#tag_with_temp option").remove();
$('#select_without option[value="' + val_none + '"]').remove();
jQuery.each($("#tag_without_temp option"), function(key, element) {
val = $(element).val();
@ -2428,7 +2437,6 @@ function reorder_tags_inputs() {
});
$("#tag_without_temp option").remove();
tags_base64 = $("#hidden-tag_with").val();
if (tags_base64.length > 0) {
tags = jQuery.parseJSON(Base64.decode(tags_base64));