diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9854f2c8093..169c24cb171 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2320,38 +2320,26 @@ class Commande extends CommonObject dol_syslog("Commande::delete sql=".$sql); if (! $this->db->query($sql) ) { - dol_syslog("CustomerOrder::delete error", LOG_ERR); + dol_syslog(get_class($this)."::delete error", LOG_ERR); $error++; } // Delete order $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; - dol_syslog("Commande::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); if (! $this->db->query($sql) ) { - dol_syslog("CustomerOrder::delete error", LOG_ERR); + dol_syslog(get_class($this)."::delete error", LOG_ERR); $error++; } // Delete linked object - // TODO deplacer dans le common - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - dol_syslog("Commande::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $error++; - } + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; // Delete linked contacts $res = $this->delete_linked_contact(); - if ($res < 0) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $error++; - } + if ($res < 0) $error++; // On efface le repertoire de pdf provisoire $comref = dol_sanitizeFileName($this->ref); @@ -2381,7 +2369,7 @@ class Commande extends CommonObject } } - if ($error == 0) + if (! $error) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ad5624f8a3f..7fcaaced30c 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1130,12 +1130,12 @@ class Facture extends CommonObject $error=0; $this->db->begin(); + + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$rowid; - $sql.= " AND targettype = '".$this->element."'"; - - if ($this->db->query($sql)) + if (! $error) { // If invoice was converted into a discount not yet consumed, we remove discount $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'societe_remise_except'; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4465d79aa06..99c19c3af7c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -294,7 +294,7 @@ abstract class CommonObject $sql.= " WHERE element_id =".$this->id; $sql.= " AND fk_c_type_contact IN (".$listId.")"; - dol_syslog(get_class($this)."::delete_linked_contact sql=".$sql); + dol_syslog(get_class($this)."::delete_linked_contact sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { return 1; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index e9fd3cfbd76..73295740d16 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -761,16 +761,16 @@ class Expedition extends CommonObject if ( $this->db->query($sql) ) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; - if ( $this->db->query($sql) ) + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition"; $sql.= " WHERE rowid = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { $this->db->commit(); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index ca3eb2cbbb1..b72df22e2de 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -585,16 +585,8 @@ class Fichinter extends CommonObject $this->db->begin(); // Delete linked object - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - dol_syslog("Fichinter::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("Fichinter::delete error", LOG_ERR); - $this->error=$this->db->lasterror(); - $error++; - } + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; // Delete linked contacts $res = $this->delete_linked_contact(); diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 72d1822e746..5d41bca48f4 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -549,15 +549,18 @@ class Livraison extends CommonObject { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); $this->db->begin(); + + $error=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet"; $sql.= " WHERE fk_livraison = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - if ( $this->db->query($sql) ) + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; + + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; $sql.= " WHERE rowid = ".$this->id;