From 950ccaa3bc5f93c2b4ce95c160c38c23d87e7b9c Mon Sep 17 00:00:00 2001 From: Paco Date: Thu, 2 Jan 2025 10:41:19 +0100 Subject: [PATCH] fix: fix `area_maintenance::register_tools` response message issues on import tools --- .../class.area_maintenance.php | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/area_maintenance/class.area_maintenance.php b/core/area_maintenance/class.area_maintenance.php index f3b9042a1..68a49d356 100644 --- a/core/area_maintenance/class.area_maintenance.php +++ b/core/area_maintenance/class.area_maintenance.php @@ -1026,6 +1026,11 @@ public static function create_test_record() : object { * REGISTER_TOOLS * Alias of tools_register::import_tools * @return object $response + * { + * result: array|false (on success, list of imported tools objects) + * msg: string + * errors: array + * } */ public static function register_tools() : object { @@ -1033,20 +1038,23 @@ public static function register_tools() : object { $response->result = false; $response->msg = 'Error. Request failed ['.__FUNCTION__.']'; - $response->result = tools_register::import_tools(); - $response->msg = 'OK. Request done successfully'; + // import_tools + $response->result = tools_register::import_tools(); // check results errors - $errors = []; - if (!empty($response->result)) { - foreach ($response->result as $item) { - if (!empty($item->errors)) { - $errors = array_merge($errors, (array)$item->errors); + $errors = []; + if (!empty($response->result)) { + foreach ($response->result as $item) { + if (!empty($item->errors)) { + $errors = array_merge($errors, (array)$item->errors); + } } } - $response->msg = 'Warning. Request done with errors'; - } - $response->errors = $errors; + $response->errors = $errors; + + $response->msg = empty($errors) + ? 'OK. Request done successfully' + : 'Warning. Request done with errors'; return $response;