From 0760d0fdafd8b6c6da2b06b4a1a7cfea4bb1e5d6 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 15 Jun 2023 08:44:53 +0200 Subject: [PATCH 1/2] #11353 Api downtime agents explode multi agents --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a8e83789aa..c4c455c7e5 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -7833,7 +7833,7 @@ function api_set_planned_downtimes_add_agents($id, $thrash1, $other, $thrash3) } if (!empty($other['data'][0])) { - $agents = $other['data']; + $agents = explode(';', $other['data'][0]); $results = false; foreach ($agents as $agent) { if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { From 13e404bcd2fcfdb032fa7421a59a33a873c3347f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 15 Jun 2023 08:56:16 +0200 Subject: [PATCH 2/2] #11353 api not null agent downtime add agent --- pandora_console/include/functions_api.php | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index c4c455c7e5..e8604928e3 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -7836,21 +7836,23 @@ function api_set_planned_downtimes_add_agents($id, $thrash1, $other, $thrash3) $agents = explode(';', $other['data'][0]); $results = false; foreach ($agents as $agent) { - if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { - $res = db_process_sql_insert( - 'tplanned_downtime_agents', - [ - 'id_agent' => $agent, - 'id_downtime' => $id, - 'all_modules' => 0, - 'manually_disabled' => 0, - ] - ); - if ($res) { - $results = true; + if (!empty($agent)) { + if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { + $res = db_process_sql_insert( + 'tplanned_downtime_agents', + [ + 'id_agent' => $agent, + 'id_downtime' => $id, + 'all_modules' => 0, + 'manually_disabled' => 0, + ] + ); + if ($res) { + $results = true; + } + } else { + returnError(" Agent $agent is already at the planned downtime."); } - } else { - returnError(" Agent $agent is already at the planned downtime."); } }