diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 4a0d966b6d2..867c0cfbc1d 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -701,75 +701,101 @@ class Adherent extends CommonObject $result = 0; $error=0; + $errorflag=0; $this->db->begin(); - // Remove extrafields - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_extrafields WHERE fk_object = ".$rowid; - + // Remove category + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid; dol_syslog(get_class($this)."::delete sql=".$sql); $resql=$this->db->query($sql); - if ($resql) + if (! $resql) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid; - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql=$this->db->query($sql); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE fk_adherent = ".$rowid; - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - // Remove linked user - $ret=$this->setUserId(0); - if ($ret > 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid; - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->affected_rows($resql)) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('MEMBER_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - - $this->db->commit(); - return 1; - } - else - { - // Rien a effacer - $this->db->rollback(); - return 0; - } - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -3; - } - } - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -2; - } + $error++; + $this->error .= $this->db->lasterror(); + $errorflag=-1; + dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); + + } + + // Remove cotisation + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."cotisation WHERE fk_adherent = ".$rowid; + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag=-2; + dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); + } + } + + // Remove linked user + if (! $error) + { + $ret=$this->setUserId(0); + if ($ret < 0) + { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag=-3; + 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) { + $error++; + $errorflag=-4; + dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); + } + } + } + + // Remove adherent + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid; + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag=-5; + dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); + } + } + + if (! $error) + { + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('MEMBER_DELETE',$this,$user,$langs,$conf); + if ($result < 0) {$error++; $this->errors=$interface->errors;} + // Fin appel triggers + } + + + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; + $this->db->rollback(); + return $errorflag; } } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 475bb42c6db..a092ab254a8 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Yann Droneaud + * Copyright (C) 2012 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -225,6 +226,10 @@ class DoliDBPgsql $line=preg_replace('/^float/i','numeric',$line); $line=preg_replace('/(\s*)float/i','\\1numeric',$line); + //Check tms timestamp field case (in Mysql this field is defautled to now and + // on update defaulted by now + $line=preg_replace('/(\s*)tms(\s*)timestamp/i','\\1tms timestamp without time zone DEFAULT now() NOT NULL',$line); + // unique index(field1,field2) if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2b6e28c55f3..38588d12090 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -626,6 +626,16 @@ 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) { + $error++; + dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); + } + } + // Delete product if (! $error) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index bd9b7cd87c6..88ca87d28e8 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1022,10 +1022,6 @@ class Societe extends CommonObject } } - // Removed extrafields - //$result=$this->deleteExtraFields($this); - //if ($result < 0) $error++; - if (! $error) { // Additionnal action by hooks @@ -1041,16 +1037,13 @@ class Societe extends CommonObject } } - // Remove extrafields - if (! $error) + // Removed extrafields + if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_extrafields WHERE fk_object = ".$id; - dol_syslog(get_class($this)."::delete sql=".$sql); - if (! $this->db->query($sql)) - { + $result=$this->deleteExtraFields($this); + if ($result < 0) { $error++; - $this->error = $this->db->lasterror(); - 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 ed91ad5beeb..510405bb614 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -717,15 +717,12 @@ class User extends CommonObject } } - // Remove extrafields - if (! $error) + // Removed extrafields + if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::delete sql=".$sql); - if (! $this->db->query($sql)) - { + $result=$this->deleteExtraFields($this); + if ($result < 0) { $error++; - $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); } }