Add a common function to delete the linked contact
This commit is contained in:
parent
54f424eedf
commit
fe62fdcf68
@ -1593,6 +1593,15 @@ class Propal extends CommonObject
|
|||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
|
||||||
if ( $this->db->query($sql) )
|
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
|
// We remove directory
|
||||||
$propalref = dol_sanitizeFileName($this->ref);
|
$propalref = dol_sanitizeFileName($this->ref);
|
||||||
if ($conf->propale->dir_output)
|
if ($conf->propale->dir_output)
|
||||||
|
|||||||
@ -1930,29 +1930,41 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Delete order details
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id;
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id;
|
||||||
dol_syslog("Commande::delete sql=".$sql);
|
dol_syslog("Commande::delete sql=".$sql);
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
dol_syslog("Commande::delete error", LOG_ERR);
|
dol_syslog("CustomerOrder::delete error", LOG_ERR);
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete order
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
|
||||||
dol_syslog("Commande::delete sql=".$sql);
|
dol_syslog("Commande::delete sql=".$sql);
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
dol_syslog("Commande::delete error", LOG_ERR);
|
dol_syslog("CustomerOrder::delete error", LOG_ERR);
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete linked object
|
||||||
|
// TODO deplacer dans le common
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element";
|
||||||
$sql.= " WHERE fk_target = ".$this->id;
|
$sql.= " WHERE fk_target = ".$this->id;
|
||||||
$sql.= " AND targettype = '".$this->element."'";
|
$sql.= " AND targettype = '".$this->element."'";
|
||||||
dol_syslog("Commande::delete sql=".$sql);
|
dol_syslog("Commande::delete sql=".$sql);
|
||||||
if (! $this->db->query($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++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1963,25 +1975,25 @@ class Commande extends CommonObject
|
|||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||||
if (file_exists($file))
|
if (file_exists($file))
|
||||||
{
|
{
|
||||||
commande_delete_preview($this->db, $this->id, $this->ref);
|
commande_delete_preview($this->db, $this->id, $this->ref);
|
||||||
|
|
||||||
if (!dol_delete_file($file))
|
if (!dol_delete_file($file))
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file_exists($dir))
|
if (file_exists($dir))
|
||||||
{
|
{
|
||||||
if (!dol_delete_dir($dir))
|
if (!dol_delete_dir($dir))
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($err == 0)
|
if ($err == 0)
|
||||||
|
|||||||
@ -625,50 +625,13 @@ class Contrat extends CommonObject
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
// Delete element_contact
|
// Delete linked contacts
|
||||||
/*
|
$res = $this->delete_linked_contact();
|
||||||
$sql = "DELETE ec";
|
if ($res < 0)
|
||||||
$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)
|
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
dol_syslog("Contract::delete error", LOG_ERR);
|
||||||
$error++;
|
$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)
|
if (! $error)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user