diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 123c3207818c4e7944071029f25a9fd7ea358f4d..41028cdbe372b56f1fafa84e4edd57b20ce16ec3 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1789,50 +1789,52 @@ class Propal extends CommonObject $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; + // Delete linked contacts $res = $this->delete_linked_contact(); - if ($res < 0) - { - $this->error='ErrorFailToDeleteLinkedContact'; - $this->db->rollback(); - return 0; - } - - // We remove directory - $propalref = dol_sanitizeFileName($this->ref); - if ($conf->propale->dir_output) + if ($res < 0) $error++; + + if (! $error) { - $dir = $conf->propale->dir_output . "/" . $propalref ; - $file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf"; - if (file_exists($file)) + // We remove directory + $propalref = dol_sanitizeFileName($this->ref); + if ($conf->propale->dir_output) { - dol_delete_preview($this); - - if (!dol_delete_file($file)) + $dir = $conf->propale->dir_output . "/" . $propalref ; + $file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf"; + if (file_exists($file)) { - $this->error='ErrorFailToDeleteFile'; - $this->db->rollback(); - return 0; + dol_delete_preview($this); + + if (!dol_delete_file($file)) + { + $this->error='ErrorFailToDeleteFile'; + $this->db->rollback(); + return 0; + } } - } - if (file_exists($dir)) - { - $res=@dol_delete_dir($dir); - if (! $res) + if (file_exists($dir)) { - $this->error='ErrorFailToDeleteDir'; - $this->db->rollback(); - return 0; + $res=@dol_delete_dir($dir); + if (! $res) + { + $this->error='ErrorFailToDeleteDir'; + $this->db->rollback(); + return 0; + } } } } - if (! $notrigger) + if (! $error && ! $notrigger) { // Call triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -1842,27 +1844,33 @@ class Propal extends CommonObject // End call triggers } - if (!$error) + if (! $error) { - dol_syslog("Suppression de la proposition $this->id par $user->id", LOG_DEBUG); + dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG); $this->db->commit(); return 1; } else { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return 0; } } else { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } } else { - $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); + $this->db->rollback(); return -1; } } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 547314759ac9a78d7807cf923428798e27bbb7dd..a8457896ed4306f928ecc751a6042e3cc8642175 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2304,9 +2304,10 @@ class Commande extends CommonObject * Delete the customer order * * @param User $user User object + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <=0 if KO, >0 if OK */ - function delete($user) + function delete($user, $notrigger=0) { global $conf, $langs; require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); @@ -2369,7 +2370,7 @@ class Commande extends CommonObject } } - if (! $error) + if (! $error && ! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -2377,12 +2378,18 @@ class Commande extends CommonObject $result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers - - $this->db->commit(); - return 1; + } + + if (! $error) + { + dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG); + $this->db->commit(); + return 1; } else { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 2abfaeb9cd87bcb7b0263b304e1bd6a922e1f189..e6175093da012271c970a08a07611e466202c887 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1116,9 +1116,10 @@ class Facture extends CommonObject * Delete invoice * * @param int $rowid Id of invoice to delete. If empty, we delete current instance of invoice + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function delete($rowid=0) + function delete($rowid, $notrigger=0) { global $user,$langs,$conf; @@ -1176,12 +1177,15 @@ class Facture extends CommonObject $resql=$this->db->query($sql); if ($resql) { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } $this->db->commit(); return 1;