From 286c3d1093e31c88a041c3af2fa4250792720f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 28 Nov 2024 12:11:50 +0100 Subject: [PATCH] fix sql ticket list (#32080) * fix sql ticket list * fix sql ticket list * fix phpstan * fix * fix --- build/phpstan/phpstan-baseline.neon | 102 --------------- htdocs/accountancy/bookkeeping/list.php | 2 + .../accountancy/bookkeeping/listbyaccount.php | 2 + htdocs/commande/class/commande.class.php | 1 + htdocs/core/actions_massactions.inc.php | 1 + htdocs/core/class/commonobject.class.php | 2 +- htdocs/expedition/class/expedition.class.php | 5 - htdocs/projet/list.php | 2 + htdocs/reception/class/reception.class.php | 4 - htdocs/salaries/payments.php | 2 + .../class/companybankaccount.class.php | 6 - htdocs/societe/list.php | 4 +- htdocs/ticket/class/ticket.class.php | 3 +- htdocs/ticket/list.php | 123 +++++++++--------- htdocs/user/list.php | 78 +++++------ 15 files changed, 116 insertions(+), 221 deletions(-) diff --git a/build/phpstan/phpstan-baseline.neon b/build/phpstan/phpstan-baseline.neon index ddc424d9d08..192a9985d69 100644 --- a/build/phpstan/phpstan-baseline.neon +++ b/build/phpstan/phpstan-baseline.neon @@ -228,12 +228,6 @@ parameters: count: 4 path: ../../htdocs/accountancy/bookkeeping/export.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../htdocs/accountancy/bookkeeping/list.php - - message: '#^Variable \$contextpage in empty\(\) always exists and is not falsy\.$#' identifier: empty.variable @@ -252,12 +246,6 @@ parameters: count: 3 path: ../../htdocs/accountancy/bookkeeping/list.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../htdocs/accountancy/bookkeeping/listbyaccount.php - - message: '#^Variable \$contextpage in empty\(\) always exists and is not falsy\.$#' identifier: empty.variable @@ -4572,12 +4560,6 @@ parameters: count: 1 path: ../../htdocs/comm/propal/class/propal.class.php - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/comm/propal/class/propal.class.php - - message: '#^Property CommonObject\:\:\$ref \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -4974,12 +4956,6 @@ parameters: count: 1 path: ../../htdocs/commande/class/commande.class.php - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/commande/class/commande.class.php - - message: '#^Property CommonObject\:\:\$ref \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -6174,12 +6150,6 @@ parameters: count: 1 path: ../../htdocs/compta/facture/class/facture.class.php - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 3 - path: ../../htdocs/compta/facture/class/facture.class.php - - message: '#^Property CommonObject\:\:\$ref \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -19368,12 +19338,6 @@ parameters: count: 2 path: ../../htdocs/expedition/class/expedition.class.php - - - message: '#^Property Expedition\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/expedition/class/expedition.class.php - - message: '#^Property Expedition\:\:\$ref_customer \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -20742,12 +20706,6 @@ parameters: count: 1 path: ../../htdocs/fourn/class/fournisseur.commande.class.php - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/fourn/class/fournisseur.commande.class.php - - message: '#^Property CommonObject\:\:\$ref_ext \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -20982,12 +20940,6 @@ parameters: count: 1 path: ../../htdocs/fourn/class/fournisseur.facture.class.php - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/fourn/class/fournisseur.facture.class.php - - message: '#^Property CommonObject\:\:\$ref_ext \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -28758,12 +28710,6 @@ parameters: count: 1 path: ../../htdocs/projet/list.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../htdocs/projet/list.php - - message: '#^Ternary operator condition is always false\.$#' identifier: ternary.alwaysFalse @@ -30654,12 +30600,6 @@ parameters: count: 2 path: ../../htdocs/reception/class/reception.class.php - - - message: '#^Property Reception\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/reception/class/reception.class.php - - message: '#^Property Reception\:\:\$ref_supplier \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -31914,12 +31854,6 @@ parameters: count: 2 path: ../../htdocs/salaries/payments.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../htdocs/salaries/payments.php - - message: '#^Ternary operator condition is always false\.$#' identifier: ternary.alwaysFalse @@ -32334,12 +32268,6 @@ parameters: count: 1 path: ../../htdocs/societe/class/companybankaccount.class.php - - - message: '#^Property CompanyBankAccount\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/societe/class/companybankaccount.class.php - - message: '#^Call to function method_exists\(\) with \$this\(Societe\) and ''getLibStatut'' will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -33738,18 +33666,6 @@ parameters: count: 1 path: ../../htdocs/ticket/class/ticket.class.php - - - message: '#^Property CommonObject\:\:\$entity \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../htdocs/ticket/class/ticket.class.php - - - - message: '#^Property CommonObject\:\:\$model_pdf \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../htdocs/ticket/class/ticket.class.php - - message: '#^Property CommonObject\:\:\$ref \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property @@ -33960,18 +33876,6 @@ parameters: count: 1 path: ../../htdocs/ticket/index.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 3 - path: ../../htdocs/ticket/list.php - - - - message: '#^Variable \$contextpage in empty\(\) always exists and is not falsy\.$#' - identifier: empty.variable - count: 1 - path: ../../htdocs/ticket/list.php - - message: '#^If condition is always false\.$#' identifier: if.alwaysFalse @@ -34320,12 +34224,6 @@ parameters: count: 2 path: ../../htdocs/user/home.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 2 - path: ../../htdocs/user/list.php - - message: '#^Offset ''u\.salary'' on array\{u\.salary\: \(float\|int\)\} in isset\(\) always exists and is not nullable\.$#' identifier: isset.offset diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index ebf0dec3396..60409e47f0f 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -495,6 +495,8 @@ if (empty($reshook)) { $permissiontodelete = $user->hasRight('societe', 'supprimer'); $permissiontoadd = $user->hasRight('societe', 'creer'); $uploaddir = $conf->societe->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) { diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 62c058fbf95..7834b2a6d0f 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -459,6 +459,8 @@ if (empty($reshook)) { $permissiontodelete = $user->hasRight('societe', 'supprimer'); $permissiontoadd = $user->hasRight('societe', 'creer'); $uploaddir = $conf->societe->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 4a6d220c49c..24532b36ba0 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -947,6 +947,7 @@ class Commande extends CommonOrder $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } + // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active $this->entity = setEntity($this); dol_syslog(get_class($this)."::create user=".$user->id); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 872aa9ae73a..94964dfae8e 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -59,6 +59,7 @@ * @var string $objectclass * @var string $uploaddir * @var string $confirm + * @var int $error */ ' @phan-var-force ?string $permissiontoread diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8fe7db58b72..7ad7702b9df 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -546,7 +546,7 @@ abstract class CommonObject public $multicurrency_total_localtax2; // not in database /** - * @var string + * @var ?string * @see SetDocModel() */ public $model_pdf; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index f7b5c2aeb3b..f80e6e5d8c7 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -136,11 +136,6 @@ class Expedition extends CommonObject */ public $billed; - /** - * @var string name of pdf model - */ - public $model_pdf; - /** * @var int|string */ diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index da8c2b669b0..9170ba31ed3 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -445,6 +445,8 @@ if (empty($reshook)) { $permissiontodelete = $user->hasRight('projet', 'supprimer'); $permissiontoadd = $user->hasRight('projet', 'creer'); $uploaddir = $conf->project->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; // Close records diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 71d4a47caff..86e8d046ff9 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -99,10 +99,6 @@ class Reception extends CommonObject * @var int<0,1> */ public $billed; - /** - * @var string - */ - public $model_pdf; /** * @var int|float diff --git a/htdocs/salaries/payments.php b/htdocs/salaries/payments.php index cc51621c14a..f91b5b3e566 100644 --- a/htdocs/salaries/payments.php +++ b/htdocs/salaries/payments.php @@ -214,6 +214,8 @@ if (empty($reshook)) { $objectclass = 'PaymentSalary'; $objectlabel = 'SalariesPayments'; $uploaddir = $conf->salaries->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; // Validate records diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index a27f7c3504a..a50c111dbfb 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -329,12 +329,6 @@ class CompanyBankAccount extends Account */ public $datem; - /** - * @var string - * @see SetDocModel() - */ - public $model_pdf; - /** * @var string TRIGGER_PREFIX Dolibarr 16.0 and above use the prefix to prevent the creation of inconsistently * named triggers diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index e5508c334e7..a8167de49da 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -480,9 +480,11 @@ if (empty($reshook)) { $permissiontodelete = $user->hasRight('societe', 'supprimer'); $permissiontoadd = $user->hasRight("societe", "creer"); $uploaddir = $conf->societe->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - if ($action == 'setstcomm' && $permissiontoadd) { + if (!$error && $action == 'setstcomm' && $permissiontoadd) { $object = new Client($db); $result = $object->fetch(GETPOST('stcommsocid')); $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm'); diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 56cfb53ef9a..b2eb7d56f7b 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -510,7 +510,8 @@ class Ticket extends CommonObject $result = $this->verify(); if ($result >= 0) { - $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); + // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active + $this->entity = setEntity($this); // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."ticket("; diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index ec492d67936..d9c82030344 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -250,19 +250,54 @@ if (empty($reshook)) { $objectclass = 'Ticket'; $objectlabel = 'Ticket'; $uploaddir = $conf->ticket->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; // Close records if (!$error && $massaction == 'close' && $permissiontoadd) { - $objecttmp = new $objectclass($db); - if (!$error) { - $db->begin(); + $objecttmp = new Ticket($db); + $db->begin(); - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - $result = $objecttmp->close($user); + $nbok = 0; + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + $result = $objecttmp->close($user); + if ($result < 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else { + $nbok++; + } + } else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (!$error) { + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + $db->commit(); + } else { + $db->rollback(); + } + //var_dump($listofobjectthirdparties);exit; + } + + // Reopen records + if (!$error && $massaction == 'reopen' && $permissiontoadd) { + $objecttmp = new Ticket($db); + $db->begin(); + + $nbok = 0; + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + if ($objecttmp->status == Ticket::STATUS_CLOSED || $objecttmp->status == Ticket::STATUS_CANCELED) { + $result = $objecttmp->setStatut(Ticket::STATUS_ASSIGNED); if ($result < 0) { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; @@ -271,62 +306,25 @@ if (empty($reshook)) { $nbok++; } } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $langs->load("errors"); + setEventMessages($langs->trans("ErrorObjectMustHaveStatusClosedToBeReOpened", $objecttmp->ref), null, 'errors'); $error++; break; } - } - - if (!$error) { - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - $db->commit(); } else { - $db->rollback(); + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; } - //var_dump($listofobjectthirdparties);exit; } - } - // Reopen records - if (!$error && $massaction == 'reopen' && $permissiontoadd) { - $objecttmp = new $objectclass($db); if (!$error) { - $db->begin(); - - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - if ($objecttmp->status == Ticket::STATUS_CLOSED || $objecttmp->status == Ticket::STATUS_CANCELED) { - $result = $objecttmp->setStatut(Ticket::STATUS_ASSIGNED); - if ($result < 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else { - $nbok++; - } - } else { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorObjectMustHaveStatusClosedToBeReOpened", $objecttmp->ref), null, 'errors'); - $error++; - break; - } - } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - } - - if (!$error) { - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - $db->commit(); - } else { - $db->rollback(); - } - //var_dump($listofobjectthirdparties);exit; + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + $db->commit(); + } else { + $db->rollback(); } + //var_dump($listofobjectthirdparties);exit; } } @@ -393,6 +391,7 @@ if ($socid > 0) { } foreach ($search as $key => $val) { + $tmpkey = 't.' . $key; if ($key == 'fk_statut' && !empty($search['fk_statut'])) { $newarrayofstatus = array(); foreach ($search['fk_statut'] as $key2 => $val2) { @@ -414,18 +413,18 @@ foreach ($search as $key => $val) { $newarrayofstatus[] = Ticket::STATUS_CANCELED; } if (count($newarrayofstatus)) { - $sql .= natural_search($key, implode(',', $newarrayofstatus), 2); + $sql .= natural_search($tmpkey, implode(',', $newarrayofstatus), 2); } continue; } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create' || $key == 'fk_project' || $key == 'fk_contract') { if ($search[$key] > 0) { - $sql .= natural_search($key, $search[$key], 2); + $sql .= natural_search($tmpkey, $search[$key], 2); } continue; } elseif ($key == 'type_code') { $newarrayoftypecodes = is_array($search[$key]) ? $search[$key] : (!empty($search[$key]) ? explode(',', $search[$key]) : array()); if (count($newarrayoftypecodes)) { - $sql .= natural_search($key, implode(',', $newarrayoftypecodes), 3); + $sql .= natural_search($tmpkey, implode(',', $newarrayoftypecodes), 3); } continue; } @@ -433,7 +432,7 @@ foreach ($search as $key => $val) { $mode_search = ((!empty($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0); // $search[$key] can be an array of values, or a string. We add filter if array not empty or if it is a string. if ((is_array($search[$key]) && !empty($search[$key])) || (!is_array($search[$key]) && $search[$key] != '')) { - $sql .= natural_search($key, $search[$key], $mode_search); + $sql .= natural_search($tmpkey, $search[$key], $mode_search); } } if ($search_all) { @@ -443,10 +442,10 @@ if ($search_societe) { $sql .= natural_search('s.nom', $search_societe); } if ($search_fk_project > 0) { - $sql .= natural_search('fk_project', (string) $search_fk_project, 2); + $sql .= natural_search('t.fk_project', (string) $search_fk_project, 2); } if ($search_fk_contract > 0) { - $sql .= natural_search('fk_contract', (string) $search_fk_contract, 2); + $sql .= natural_search('t.fk_contract', (string) $search_fk_contract, 2); } if ($search_date_start) { $sql .= " AND t.datec >= '".$db->idate($search_date_start)."'"; @@ -661,7 +660,7 @@ $param = ''; if (!empty($mode)) { $param .= '&mode='.urlencode($mode); } -if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { +if (/* !empty($contextpage) && */ $contextpage != $_SERVER["PHP_SELF"]) { // $contextpage can't be empty $param .= '&contextpage='.urlencode($contextpage); } if ($limit > 0 && $limit != $conf->liste_limit) { diff --git a/htdocs/user/list.php b/htdocs/user/list.php index 36d0a7df8d9..fb0712c7482 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -304,63 +304,63 @@ if (empty($reshook)) { $objectclass = 'User'; $objectlabel = 'User'; $uploaddir = $conf->user->dir_output; + + global $error; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; // Disable or Enable records if (!$error && ($massaction == 'disable' || $massaction == 'reactivate') && $permissiontoadd) { $objecttmp = new User($db); - if (!$error) { - $db->begin(); + $db->begin(); - $nbok = 0; - foreach ($toselect as $toselectid) { - if ($toselectid == $user->id) { - setEventMessages($langs->trans($massaction == 0 ? 'CantDisableYourself' : 'CanEnableYourself'), null, 'errors'); + $nbok = 0; + foreach ($toselect as $toselectid) { + if ($toselectid == $user->id) { + setEventMessages($langs->trans($massaction == 0 ? 'CantDisableYourself' : 'CanEnableYourself'), null, 'errors'); + $error++; + break; + } + + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + if ($objecttmp->admin) { + setEventMessages($langs->trans($massaction == 0 ? 'CantDisableAnAdminUserWithMassActions' : 'CantEnableAnAdminUserWithMassActions', $objecttmp->login), null, 'errors'); $error++; break; } - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - if ($objecttmp->admin) { - setEventMessages($langs->trans($massaction == 0 ? 'CantDisableAnAdminUserWithMassActions' : 'CantEnableAnAdminUserWithMassActions', $objecttmp->login), null, 'errors'); - $error++; - break; - } - - $result = $objecttmp->setstatus($massaction == 'disable' ? 0 : 1); - if ($result == 0) { - // Nothing is done - } elseif ($result < 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else { - $nbok++; - } - } else { + $result = $objecttmp->setstatus($massaction == 'disable' ? 0 : 1); + if ($result == 0) { + // Nothing is done + } elseif ($result < 0) { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; break; + } else { + $nbok++; } - } - - if (!$error && !empty($conf->file->main_limit_users)) { - $nb = $object->getNbOfUsers("active"); - if ($nb >= $conf->file->main_limit_users) { - $error++; - setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors'); - } - } - - if (!$error) { - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - $db->commit(); } else { - $db->rollback(); + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; } } + + if (!$error && !empty($conf->file->main_limit_users)) { + $nb = $object->getNbOfUsers("active"); + if ($nb >= $conf->file->main_limit_users) { + $error++; + setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors'); + } + } + + if (!$error) { + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + $db->commit(); + } else { + $db->rollback(); + } } }