From 4e78a24a133546ef052b8e1bebba0e4e22cdd8b0 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Thu, 9 Sep 2021 11:25:46 +0200 Subject: [PATCH] FIX : if delete return < 0, we break and rollback, if == 0, we set event message warning and we test other objects of list --- htdocs/core/actions_massactions.inc.php | 35 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index eb3173e0cef..8ca41166759 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1315,10 +1315,12 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' $result = $objecttmp->delete($user); } - if ($result <= 0) { - + if(empty($result)) { // if delete returns 0, there is at least one object linked $TMsg = array_merge($objecttmp->errors, $TMsg); + } elseif ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; + break; } else { $nbok++; } @@ -1329,19 +1331,26 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' } } - // Message for elements well deleted - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); - } elseif(!empty($nbok)) { - setEventMessages($langs->trans("RecordsDeleted", '1'), null, 'mesgs'); - } - $db->commit(); + if (empty($error)) { + // Message for elements well deleted + if ($nbok > 1) { + setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + } elseif (!empty($nbok)) { + setEventMessages($langs->trans("RecordsDeleted", '1'), null, 'mesgs'); + } - // Message for elements which can't be deleted - if (!empty($error)) { - sort($TMsg); - setEventMessages('', array_unique($TMsg), 'errors'); + // Message for elements which can't be deleted + if (!empty($TMsg)) { + sort($TMsg); + setEventMessages('', array_unique($TMsg), 'warnings'); + } + + $db->commit(); + + } else { + $db->rollback(); } + //var_dump($listofobjectthirdparties);exit; }