From c3da1554a7edb6cf59d83ee69b52141b08a1d7ed Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Feb 2023 16:28:04 +0100 Subject: [PATCH] Debug v17 --- htdocs/core/actions_massactions.inc.php | 9 ++- htdocs/projet/class/project.class.php | 76 +++++++++++++------------ htdocs/projet/list.php | 1 + 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index d5731f014af..3338acd1be4 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -958,7 +958,14 @@ if (!$error && $massaction == 'validate' && $permissiontoadd) { foreach ($toselect as $toselectid) { $result = $objecttmp->fetch($toselectid); if ($result > 0) { - $result = $objecttmp->validate($user); + if (method_exists($objecttmp, 'validate')) { + $result = $objecttmp->validate($user); + } elseif (method_exists($objecttmp, 'setValid')) { + $result = $objecttmp->setValid($user); + } else { + $objecttmp->error = 'No method validate or setValid on this object'; + $result = -1; + } if ($result == 0) { $langs->load("errors"); setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors'); diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 0d6df2ddc98..5375a418ca2 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1098,7 +1098,7 @@ class Project extends CommonObject * * @param User $user User that validate * @param int $notrigger 1=Disable triggers - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, 0=Nothing done, >0 if KO */ public function setValid($user, $notrigger = 0) { @@ -1106,47 +1106,51 @@ class Project extends CommonObject $error = 0; - if ($this->statut != 1) { - // Check parameters - if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) { - $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf")); - return -1; + // Protection + if ($this->status == self::STATUS_VALIDATED) { + dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING); + return 0; + } + + // Check parameters + if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->title)) { + $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("Label")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf")); + return -1; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."projet"; + $sql .= " SET fk_statut = ".self::STATUS_VALIDATED; + $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " AND entity = ".((int) $conf->entity); + + dol_syslog(get_class($this)."::setValid", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + // Call trigger + if (empty($notrigger)) { + $result = $this->call_trigger('PROJECT_VALIDATE', $user); + if ($result < 0) { + $error++; + } + // End call triggers } - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."projet"; - $sql .= " SET fk_statut = 1"; - $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= " AND entity = ".((int) $conf->entity); - - dol_syslog(get_class($this)."::setValid", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - // Call trigger - if (empty($notrigger)) { - $result = $this->call_trigger('PROJECT_VALIDATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $this->statut = 1; - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - $this->error = join(',', $this->errors); - dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR); - return -1; - } + if (!$error) { + $this->statut = 1; + $this->db->commit(); + return 1; } else { $this->db->rollback(); - $this->error = $this->db->lasterror(); + $this->error = join(',', $this->errors); + dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR); return -1; } + } else { + $this->db->rollback(); + $this->error = $this->db->lasterror(); + return -1; } } diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index c50350c91cc..15fc35f9e84 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -888,6 +888,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; // List of mass actions available $arrayofmassactions = array( + 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"), 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),