From ee7aacae54428212ee2a31155e327405cd0e68e6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jan 2021 15:19:56 +0100 Subject: [PATCH 1/5] More complete error message --- htdocs/societe/class/societe.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 62815300437..9b224200060 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3750,9 +3750,8 @@ class Societe extends CommonObject if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" $state_code = $tmp[1]; $state_label = $tmp[2]; - } else // For backward compatibility - { - dol_syslog("Your state setup use an old syntax. Reedit it using setup area.", LOG_ERR); + } else { // For backward compatibility + dol_syslog("Your state setup use an old syntax (entity=".$conf->entity."). Reedit it using setup area.", LOG_ERR); include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $state_code = getState($state_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore $state_label = getState($state_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore From 0d704b07143e1d7f9579854eed75552555fdf66b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jan 2021 19:09:57 +0100 Subject: [PATCH 2/5] FIX error managent and db transaction balance --- htdocs/commande/class/commande.class.php | 6 ++++-- htdocs/compta/paiement/class/paiement.class.php | 1 + htdocs/core/class/interfaces.class.php | 17 +++++++++++++---- .../fourn/class/fournisseur.commande.class.php | 8 +++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 3cc0fa72ae6..908a7d3b175 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2896,19 +2896,21 @@ class Commande extends CommonOrder * Classify the order as invoiced * * @param User $user Object user making the change - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int <0 if KO, >0 if OK + * @param int $notrigger 1=Does not execute triggers, 0=execute triggers + * @return int <0 if KO, 0 if already billed, >0 if OK */ public function classifyBilled(User $user, $notrigger = 0) { $error = 0; $this->db->begin(); + if ($this->billed) { return 0; } + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 89737ca917f..2c897968320 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -401,6 +401,7 @@ class Paiement extends CommonObject if ($result < 0) { $this->error = $invoice->error; + $this->errors = $invoice->errors; $error++; } } diff --git a/htdocs/core/class/interfaces.class.php b/htdocs/core/class/interfaces.class.php index 19965250727..534d6b5803e 100644 --- a/htdocs/core/class/interfaces.class.php +++ b/htdocs/core/class/interfaces.class.php @@ -179,20 +179,29 @@ class Interfaces $objMod = new $modName($this->db); if ($objMod) { + $dblevelbefore = $this->db->transaction_opened; + $result = 0; - if (method_exists($objMod, 'runTrigger')) // New method to implement - { + if (method_exists($objMod, 'runTrigger')) { // New method to implement //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG); $result = $objMod->runTrigger($action, $object, $user, $langs, $conf); - } elseif (method_exists($objMod, 'run_trigger')) // Deprecated method - { + } elseif (method_exists($objMod, 'run_trigger')) { // Deprecated method dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING); $result = $objMod->run_trigger($action, $object, $user, $langs, $conf); } else { dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR); } + $dblevelafter = $this->db->transaction_opened; + + if ($dblevelbefore != $dblevelafter) { + $errormessage = "Error, the balance begin/close of db transactions has been broken into trigger ".$modName." with action=".$action." before=".$dblevelbefore." after=".$dblevelafter; + $this->errors[] = $errormessage; + dol_syslog($errormessage, LOG_ERR); + $result = -1; + } + if ($result > 0) { // Action OK diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 5464116c1ed..ee8fa746107 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -891,11 +891,17 @@ class CommandeFournisseur extends CommonOrder * Class invoiced the supplier order * * @param User $user Object user making the change - * @return int <0 if KO, >0 if KO + * @return int <0 if KO, 0 if already billed, >0 if OK */ public function classifyBilled(User $user) { $error = 0; + + if ($this->billed) + { + return 0; + } + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; From bcfe03216ae7b988949b62b6c83e9e1ccee66864 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jan 2021 19:15:54 +0100 Subject: [PATCH 3/5] FIX error managent and db transaction balance --- htdocs/commande/class/commande.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 908a7d3b175..7ed6d5e7199 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2903,13 +2903,12 @@ class Commande extends CommonOrder { $error = 0; - $this->db->begin(); - if ($this->billed) { return 0; } + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; From c6c7cbf208b7c0018200183dbc1cd01be6e690d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 15 Jan 2021 11:21:47 +0100 Subject: [PATCH 4/5] Fix trans --- htdocs/install/check.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 06e9e5147e9..97ddb315ca9 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -122,7 +122,7 @@ if (!function_exists("imagecreate")) print 'Error '.$langs->trans("ErrorPHPDoesNotSupportGD")."
\n"; // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) } else { - print 'Ok '.$langs->trans("PHPSupportGD")."
\n"; + print 'Ok '.$langs->trans("PHPSupport", "GD")."
\n"; } @@ -133,7 +133,7 @@ if (!function_exists("curl_init")) print 'Error '.$langs->trans("ErrorPHPDoesNotSupportCurl")."
\n"; // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) } else { - print 'Ok '.$langs->trans("PHPSupportCurl")."
\n"; + print 'Ok '.$langs->trans("PHPSupport", "Curl")."
\n"; } // Check if PHP calendar extension is available @@ -141,7 +141,7 @@ if (!function_exists("easter_date")) { print 'Error '.$langs->trans("ErrorPHPDoesNotSupportCalendar")."
\n"; } else { - print 'Ok '.$langs->trans("PHPSupportCalendar")."
\n"; + print 'Ok '.$langs->trans("PHPSupport", "Calendar")."
\n"; } @@ -152,7 +152,7 @@ if (!function_exists("utf8_encode")) print 'Error '.$langs->trans("ErrorPHPDoesNotSupportUTF8")."
\n"; // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) } else { - print 'Ok '.$langs->trans("PHPSupportUTF8")."
\n"; + print 'Ok '.$langs->trans("PHPSupport", "UTF8")."
\n"; } @@ -165,7 +165,7 @@ if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@loc print 'Error '.$langs->trans("ErrorPHPDoesNotSupportIntl")."
\n"; // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install) } else { - print 'Ok '.$langs->trans("PHPSupportIntl")."
\n"; + print 'Ok '.$langs->trans("PHPSupport", "Intl")."
\n"; } } From 6db640d0d0b4412e261ae31f0d63f05476e319a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 15 Jan 2021 11:41:09 +0100 Subject: [PATCH 5/5] Fix phpcs --- htdocs/projet/graph_opportunities.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/graph_opportunities.inc.php b/htdocs/projet/graph_opportunities.inc.php index 6d0bec6255d..9588951307a 100644 --- a/htdocs/projet/graph_opportunities.inc.php +++ b/htdocs/projet/graph_opportunities.inc.php @@ -68,7 +68,7 @@ if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) $listofstatus = array_keys($listofoppstatus); // Complete with values found into database and not into the dictionary - foreach($valsamount as $key => $val) { + foreach ($valsamount as $key => $val) { if (!in_array($key, $listofstatus)) { $listofstatus[] = $key; }