From 9d33fa08fee95ee36014bb96b24cf94e56cc1ec5 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 26 Jul 2022 07:57:04 +0200 Subject: [PATCH] fix error collation events pandora_enterprise#9290 --- pandora_console/include/functions_events.php | 40 ++++++++++++++------ 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index b34a313737..18cc4d3118 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1091,18 +1091,36 @@ function events_get_all( // Custom data. if (empty($filter['custom_data']) === false) { - if ($filter['custom_data_filter_type'] === '1') { - $sql_filters[] = sprintf( - ' AND JSON_VALID(custom_data) = 1 - AND (JSON_EXTRACT(custom_data, "$.*") LIKE lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) ', - io_safe_output($filter['custom_data']) - ); + if (isset($config['dbconnection']->server_version) === true + && $config['dbconnection']->server_version > 50600 + ) { + if ($filter['custom_data_filter_type'] === '1') { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 + AND (JSON_EXTRACT(custom_data, "$.*") LIKE lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) ', + io_safe_output($filter['custom_data']) + ); + } else { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 + AND (JSON_SEARCH(JSON_KEYS(custom_data), "all", lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) IS NOT NULL) ', + io_safe_output($filter['custom_data']) + ); + } } else { - $sql_filters[] = sprintf( - ' AND JSON_VALID(custom_data) = 1 - AND (JSON_SEARCH(JSON_KEYS(custom_data), "all", lower("%%%s%%") COLLATE utf8mb4_0900_ai_ci) IS NOT NULL) ', - io_safe_output($filter['custom_data']) - ); + if ($filter['custom_data_filter_type'] === '1') { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 AND JSON_EXTRACT(custom_data, "$.*") LIKE lower("%%%s%%") ', + $filter['custom_data'], + $filter['custom_data'] + ); + } else { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 AND JSON_KEYS(custom_data) REGEXP "%s" ', + $filter['custom_data'], + $filter['custom_data'] + ); + } } }