From 84ef61596dcd24b9c1e83b8f32c9ca2887a81fa1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Jan 2026 23:02:53 +0100 Subject: [PATCH 1/3] Better log --- htdocs/emailcollector/class/emailcollector.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 1ef8de831f6..5ba75ed438b 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1025,24 +1025,25 @@ class EmailCollector extends CommonObject } } } + if (preg_match('/^options_/', $tmpproperty)) { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->array_options[preg_replace('/^options_/', '', $tmpproperty)], 128)); + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->array_options[preg_replace('/^options_/', '', $tmpproperty)], 128)).' so object extrafield '.dol_escape_htmltag($tmpproperty).' is set.'; } else { if (property_exists($object, $tmpproperty)) { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->$tmpproperty, 128)); + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->$tmpproperty, 128)).' so object property '.dol_escape_htmltag($tmpproperty).' is set.'; } else { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($tmp[$tmpproperty], 128)); + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($tmp[$tmpproperty], 128)).' so var '.dol_escape_htmltag($tmpproperty).' is set.'; } } } else { // Regex not found if (property_exists($object, $tmpproperty)) { $object->$tmpproperty = null; + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> not found, so object property '.dol_escape_htmltag($tmpproperty).' is set to null.'; } else { $tmp[$tmpproperty] = null; + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> not found, so var '.dol_escape_htmltag($tmpproperty).' is set to null.'; } - - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> not found, so property '.dol_escape_htmltag($tmpproperty).' is set to null.'; } } else { // Nothing can be done for this param From abb195ff68ed2efcad90d52e816de0982219a5da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Jan 2026 23:04:33 +0100 Subject: [PATCH 2/3] Log --- htdocs/emailcollector/class/emailcollector.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 5ba75ed438b..177aedaf291 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1027,12 +1027,12 @@ class EmailCollector extends CommonObject } if (preg_match('/^options_/', $tmpproperty)) { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->array_options[preg_replace('/^options_/', '', $tmpproperty)], 128)).' so object extrafield '.dol_escape_htmltag($tmpproperty).' is set.'; + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> extract '.dol_escape_htmltag(dol_trunc($object->array_options[preg_replace('/^options_/', '', $tmpproperty)], 128)).' so object extrafield '.dol_escape_htmltag($tmpproperty).' is set.'; } else { if (property_exists($object, $tmpproperty)) { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($object->$tmpproperty, 128)).' so object property '.dol_escape_htmltag($tmpproperty).' is set.'; + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> extract '.dol_escape_htmltag(dol_trunc($object->$tmpproperty, 128)).' so object property '.dol_escape_htmltag($tmpproperty).' is set.'; } else { - $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> found '.dol_escape_htmltag(dol_trunc($tmp[$tmpproperty], 128)).' so var '.dol_escape_htmltag($tmpproperty).' is set.'; + $operationslog .= '
Regex /'.dol_escape_htmltag($regexstring).'/'.dol_escape_htmltag($regexoptions).' into '.strtolower($sourcefield).' -> extract '.dol_escape_htmltag(dol_trunc($tmp[$tmpproperty], 128)).' so var '.dol_escape_htmltag($tmpproperty).' is set.'; } } } else { From 47f8bec9ce107f9fbbfb13fdd985649e74ebcffd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Jan 2026 23:28:49 +0100 Subject: [PATCH 3/3] 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);