From f4459ee1f13a8abfe758edf1c290293f8bb0bd43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Dec 2012 19:06:59 +0100 Subject: [PATCH] Fix: Regression detected by PHPUnit --- htdocs/adherents/class/adherent.class.php | 25 ++++++++++--------- htdocs/comm/action/class/actioncomm.class.php | 18 +++++++------ htdocs/core/class/commonobject.class.php | 21 ++++++++-------- htdocs/product/class/product.class.php | 5 ++-- htdocs/societe/class/societe.class.php | 9 ++++--- htdocs/user/class/user.class.php | 5 ++-- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 867c0cfbc1d..c1a6769216b 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -715,9 +715,9 @@ class Adherent extends CommonObject $this->error .= $this->db->lasterror(); $errorflag=-1; dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); - + } - + // Remove cotisation if (! $error) { @@ -732,9 +732,9 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); } } - + // Remove linked user - if (! $error) + if (! $error) { $ret=$this->setUserId(0); if ($ret < 0) @@ -745,21 +745,22 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); } } - + // Removed extrafields if (! $error) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->deleteExtraFields($this); - if ($result < 0) { + $result=$this->deleteExtraFields(); + if ($result < 0) + { $error++; $errorflag=-4; dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); } } } - + // Remove adherent if (! $error) { @@ -774,7 +775,7 @@ class Adherent extends CommonObject dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); } } - + if (! $error) { // Appel des triggers @@ -784,9 +785,9 @@ class Adherent extends CommonObject if ($result < 0) {$error++; $this->errors=$interface->errors;} // Fin appel triggers } - - - + + + if (! $error) { $this->db->commit(); diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 489c9d2409d..dfc80a04051 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -227,7 +227,7 @@ class ActionComm extends CommonObject } } else if ($reshook < 0) $error++; - + if (! $notrigger) { // Appel des triggers @@ -367,13 +367,17 @@ class ActionComm extends CommonObject $this->error=$this->db->lasterror(); $error++; } - + // Removed extrafields if (! $error) { - $result=$this->deleteExtraFields($this); - if ($result < 0) $error++; + $result=$this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); + } } - + if (!$error) { if (! $notrigger) @@ -468,7 +472,7 @@ class ActionComm extends CommonObject dol_syslog(get_class($this)."::update sql=".$sql); if ($this->db->query($sql)) { - + // Actions on extra fields (by external module or standard code) include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager=new HookManager($this->db); @@ -487,7 +491,7 @@ class ActionComm extends CommonObject } } else if ($reshook < 0) $error++; - + if (! $notrigger) { // Appel des triggers diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 75a5086e711..4147bdf2fb6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2069,25 +2069,24 @@ abstract class CommonObject /** * Delete all extra fields values for the current object. - * - * @return void + * + * @return int <0 if KO, >0 if OK */ function deleteExtraFields() { global $langs; - + $error=0; - + $this->db->begin(); - + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del); - $this->db->query($sql_del); - + dol_syslog(get_class($this)."::deleteExtraFields delete sql=".$sql_del); + $resql=$this->db->query($sql_del); if (! $resql) { $this->error=$this->db->lasterror(); - dol_syslog(get_class($this)."::delete ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::deleteExtraFields ".$this->error,LOG_ERR); $this->db->rollback(); return -1; } @@ -2256,7 +2255,7 @@ abstract class CommonObject /** * Function that returns the total amount of discounts applied. - * + * * @return false|float False is returned if the discount couldn't be retrieved */ function getTotalDiscount() @@ -2264,7 +2263,7 @@ abstract class CommonObject $sql = 'SELECT (SUM(`subprice`) - SUM(`total_ht`)) as `discount` FROM '.MAIN_DB_PREFIX.$this->table_element.'det WHERE `'.$this->fk_element.'` = '.$this->id; $query = $this->db->query($sql); - + if ($query) { $result = $this->db->fetch_object($query); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 38588d12090..daff25aebc1 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -629,8 +629,9 @@ class Product extends CommonObject // Removed extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $result=$this->deleteExtraFields($this); - if ($result < 0) { + $result=$this->deleteExtraFields(); + if ($result < 0) + { $error++; dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 88ca87d28e8..ee26d047ba6 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1018,7 +1018,7 @@ class Societe extends CommonObject { $error++; $this->error = $this->db->lasterror(); - dol_syslog(get_class($this)."::Delete erreur -2 ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::delete erreur -2 ".$this->error, LOG_ERR); } } @@ -1040,10 +1040,11 @@ class Societe extends CommonObject // Removed extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $result=$this->deleteExtraFields($this); - if ($result < 0) { + $result=$this->deleteExtraFields(); + if ($result < 0) + { $error++; - dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 35265d42f8d..805090d3956 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -721,8 +721,9 @@ class User extends CommonObject // Remove extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $result=$this->deleteExtraFields($this); - if ($result < 0) { + $result=$this->deleteExtraFields(); + if ($result < 0) + { $error++; dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); }