From fe62fdcf68f07d314b78e49d4d104918be152779 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 29 Apr 2010 15:57:57 +0000 Subject: [PATCH] Add a common function to delete the linked contact --- htdocs/comm/propal/class/propal.class.php | 9 ++++ htdocs/commande/class/commande.class.php | 56 ++++++++++++++--------- htdocs/contrat/class/contrat.class.php | 45 ++---------------- 3 files changed, 47 insertions(+), 63 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 7493b96b43a..976589dc8a5 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1593,6 +1593,15 @@ class Propal extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; if ( $this->db->query($sql) ) { + // 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) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 88bf556956c..789b94a3572 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1930,29 +1930,41 @@ class Commande extends CommonObject $this->db->begin(); + // Delete order details $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id; dol_syslog("Commande::delete sql=".$sql); if (! $this->db->query($sql) ) { - dol_syslog("Commande::delete error", LOG_ERR); + dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } + // Delete order $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; dol_syslog("Commande::delete sql=".$sql); if (! $this->db->query($sql) ) { - dol_syslog("Commande::delete error", LOG_ERR); + dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } + // 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("Commande::delete error", LOG_ERR); + dol_syslog("CustomerOrder::delete error", LOG_ERR); + $err++; + } + + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) + { + dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } @@ -1963,25 +1975,25 @@ class Commande extends CommonObject $dir = $conf->commande->dir_output . "/" . $comref ; $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) - { - commande_delete_preview($this->db, $this->id, $this->ref); - - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - $this->db->rollback(); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - $this->db->rollback(); - return 0; - } - } + { + commande_delete_preview($this->db, $this->id, $this->ref); + + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + $this->db->rollback(); + return 0; + } + } } if ($err == 0) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index dd8f8b4e435..759ca4b06be 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -625,50 +625,13 @@ class Contrat extends CommonObject if (! $error) { - // Delete element_contact - /* - $sql = "DELETE ec"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.fk_c_type_contact = tc.rowid"; - $sql.= " AND tc.element='".$this->element."'"; - $sql.= " AND ec.element_id=".$this->id; - */ - - $sql = "SELECT ec.rowid as ecrowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql.= " WHERE ec.fk_c_type_contact = tc.rowid"; - $sql.= " AND tc.element='".$this->element."'"; - $sql.= " AND ec.element_id=".$this->id; - - dol_syslog("Contrat::delete element_contact sql=".$sql,LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) { - $this->error=$this->db->error(); + dol_syslog("Contract::delete error", LOG_ERR); $error++; } - $numressql=$this->db->num_rows($resql); - if (! $error && $numressql ) - { - $tab_resql=array(); - for($i=0;$i<$numressql;$i++) - { - $objresql=$this->db->fetch_object($resql); - $tab_resql[]= $objresql->ecrowid; - } - $this->db->free($resql); - - $sql= "DELETE FROM ".MAIN_DB_PREFIX."element_contact "; - $sql.= " WHERE ".MAIN_DB_PREFIX."element_contact.rowid IN (".implode(",",$tab_resql).")"; - - dol_syslog("Contrat::delete element_contact sql=".$sql,LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->error(); - $error++; - } - } } if (! $error)