From 47f8bec9ce107f9fbbfb13fdd985649e74ebcffd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Jan 2026 23:28:49 +0100 Subject: [PATCH] Better error management --- htdocs/emailcollector/class/emailcollector.class.php | 5 +++-- htdocs/societe/class/societe.class.php | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 177aedaf291..bde583ce11c 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -2691,7 +2691,8 @@ class EmailCollector extends CommonObject $this->error = 'Error when getting thirdparty with name '.$nametouseforthirdparty.' (may be 2 record exists with same name ?)'; $this->errors[] = $this->error; break; - } elseif ($result == 0) { // No thirdparty found + } + if ($result == 0) { // No thirdparty found if ($operation['type'] == 'loadthirdparty') { dol_syslog("Third party with id=".$idtouseforthirdparty." email=".$emailtouseforthirdparty." name=".$nametouseforthirdparty." name_alias=".$namealiastouseforthirdparty." was not found"); @@ -2753,7 +2754,7 @@ class EmailCollector extends CommonObject } } } - } else { // $result > 0 is ID of thirdparty + } else { // if $result > 0, it is ID of thirdparty dol_syslog("One and only one existing third party has been found"); $thirdpartystatic->fetch($result); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c947426fc41..60240fa1fce 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1913,7 +1913,7 @@ class Societe extends CommonObject * @param string $ref_alias Name_alias of third party (Warning, this can return several records) * @param int $is_client Only client third party * @param int $is_supplier Only supplier third party - * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. + * @return int >0 if OK, <0 if KO (-2 if two records found for same ref or idprof, other negative for error), 0 if not found. */ public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 0, $is_supplier = 0) { @@ -2042,7 +2042,7 @@ class Societe extends CommonObject $num = $this->db->num_rows($resql); if ($num > 1) { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; - dol_syslog($this->error, LOG_ERR); + dol_syslog($this->error, LOG_WARNING); $result = -2; } elseif ($num) { // $num = 1 $obj = $this->db->fetch_object($resql); @@ -2241,7 +2241,7 @@ class Societe extends CommonObject * @param string $ref_alias Name_alias of third party (Warning, this can return several records) * @param int $is_client Only client third party * @param int $is_supplier Only supplier third party - * @return int ID of thirdparty found if OK, <0 if KO or if two records found, 0 if not found. + * @return int ID of thirdparty found if OK, <0 if KO (-2 if two records found or other negative if error), 0 if not found. */ public function findNearest($rowid = 0, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 0, $is_supplier = 0) { @@ -2321,7 +2321,7 @@ class Societe extends CommonObject $num = $this->db->num_rows($resql); if ($num > 1) { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; - dol_syslog($this->error, LOG_ERR); + dol_syslog($this->error, LOG_WARNING); $result = -2; } elseif ($num) { $obj = $this->db->fetch_object($resql); @@ -2374,7 +2374,7 @@ class Societe extends CommonObject $num = $this->db->num_rows($resql); if ($num > 1) { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; - dol_syslog($this->error, LOG_ERR); + dol_syslog($this->error, LOG_WARNING); $result = -2; } elseif ($num) { $obj = $this->db->fetch_object($resql);