From 938092d67c80d01dbfd7d48d9624b438b29c1b79 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Tue, 7 Sep 2021 16:46:48 +0200 Subject: [PATCH 1/5] NEW : when we delete several objects with massaction, if somes object has child we must see which objects are concerned and nevertheless delete objects which can be deleted --- htdocs/core/actions_massactions.inc.php | 26 ++++++++++++++---------- htdocs/core/class/commonobject.class.php | 4 ++-- htdocs/langs/en_US/errors.lang | 2 +- htdocs/langs/fr_FR/errors.lang | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 23851b5e789..eb3173e0cef 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1287,6 +1287,7 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' $objecttmp = new $objectclass($db); $nbok = 0; + $TMsg = array(); foreach ($toselect as $toselectid) { $result = $objecttmp->fetch($toselectid); if ($result > 0) { @@ -1315,9 +1316,9 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' } if ($result <= 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + + $TMsg = array_merge($objecttmp->errors, $TMsg); $error++; - break; } else { $nbok++; } @@ -1328,15 +1329,18 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' } } - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); + // 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(); + + // Message for elements which can't be deleted + if (!empty($error)) { + sort($TMsg); + setEventMessages('', array_unique($TMsg), 'errors'); } //var_dump($listofobjectthirdparties);exit; } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5cdb83194f4..8d198578fe5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4292,10 +4292,10 @@ abstract class CommonObject //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; $haschild += $obj->nb; if (is_numeric($elementname)) { // old usage - $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); + $this->errors[] = $langs->transnoentities("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $table); } else // new usage: $elementname=Translation key { - $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); + $this->errors[] = $langs->transnoentities("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($elementname)); } break; // We found at least one, we stop here } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 89a3ec36af5..303df972340 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -83,7 +83,7 @@ ErrorCantSaveADoneUserWithZeroPercentage=Can't save an action with "status not s ErrorRefAlreadyExists=Ref used for creation already exists. ErrorPleaseTypeBankTransactionReportName=Please enter the bank statement name where the entry has to be reported (Format YYYYMM or YYYYMMDD) ErrorRecordHasChildren=Failed to delete record since it has some child records. -ErrorRecordHasAtLeastOneChildOfType=Object has at least one child of type %s +ErrorRecordHasAtLeastOneChildOfType=Object %s has at least one child of type %s ErrorRecordIsUsedCantDelete=Can't delete record. It is already used or included into another object. ErrorModuleRequireJavascript=Javascript must not be disabled to have this feature working. To enable/disable Javascript, go to menu Home->Setup->Display. ErrorPasswordsMustMatch=Both typed passwords must match each other diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index d7955df97e6..32090a13126 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -83,7 +83,7 @@ ErrorCantSaveADoneUserWithZeroPercentage=Impossible de sauver une action à l'é ErrorRefAlreadyExists=Le référence %s existe déjà. ErrorPleaseTypeBankTransactionReportName=Choisissez le nom du relevé bancaire sur lequel la ligne est rapportées (Format AAAAMM ou AAAAMMJJ) ErrorRecordHasChildren=Impossible de supprimer l'enregistrement car il possède des enregistrements fils. -ErrorRecordHasAtLeastOneChildOfType=L'objet a au moins un enfant de type %s +ErrorRecordHasAtLeastOneChildOfType=L'objet %s a au moins un enfant de type %s ErrorRecordIsUsedCantDelete=Ne peut effacer l'enregistrement. Ce dernier est déjà utilisé ou inclut dans un autre élément. ErrorModuleRequireJavascript=Le javascript ne doit pas être désactivé pour que cette fonctionnalité soit utilisable. Pour activer/désactiver l'utilisation de javascript, allez dans le menu Accueil->Configuration->Affichage. ErrorPasswordsMustMatch=Les 2 mots de passe saisis doivent correspondre From e94c560e829c60f3254e720675a160ce18bbcd5e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 7 Sep 2021 14:55:49 +0000 Subject: [PATCH 2/5] Fixing style errors. --- htdocs/core/actions_massactions.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index eb3173e0cef..87e3947c793 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1316,7 +1316,6 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' } if ($result <= 0) { - $TMsg = array_merge($objecttmp->errors, $TMsg); $error++; } else { @@ -1332,7 +1331,7 @@ 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)) { + } elseif (!empty($nbok)) { setEventMessages($langs->trans("RecordsDeleted", '1'), null, 'mesgs'); } $db->commit(); 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 3/5] 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; } From 1e8870eb95fe295c9d53e21cba93c2e924ecdf9c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 9 Sep 2021 09:30:29 +0000 Subject: [PATCH 4/5] Fixing style errors. --- htdocs/core/actions_massactions.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 8ca41166759..be7528b2a4e 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1315,7 +1315,7 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' $result = $objecttmp->delete($user); } - if(empty($result)) { // if delete returns 0, there is at least one object linked + 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'); @@ -1346,7 +1346,6 @@ if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == ' } $db->commit(); - } else { $db->rollback(); } From d9cdddd688edcf2186ae954a0e52201ae2343cc1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Sep 2021 14:35:19 +0200 Subject: [PATCH 5/5] Update actions_massactions.inc.php --- htdocs/core/actions_massactions.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index be7528b2a4e..d10cd2d2f02 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1335,8 +1335,8 @@ 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'); + } elseif ($nbok == 1) { + setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); } // Message for elements which can't be deleted