Fix: delete linked object in propal delete function and uniformize code

This commit is contained in:
Regis Houssin 2012-02-13 18:27:42 +01:00
parent f07b6397fc
commit 6f3f1204fe
3 changed files with 64 additions and 45 deletions

View File

@ -1794,15 +1794,16 @@ 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 object
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
// Delete linked contacts // Delete linked contacts
$res = $this->delete_linked_contact(); $res = $this->delete_linked_contact();
if ($res < 0) if ($res < 0) $error++;
{
$this->error='ErrorFailToDeleteLinkedContact';
$this->db->rollback();
return 0;
}
if (! $error)
{
// 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)
@ -1831,8 +1832,9 @@ class Propal extends CommonObject
} }
} }
} }
}
if (! $notrigger) if (! $error && ! $notrigger)
{ {
// Call triggers // Call triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@ -1844,24 +1846,30 @@ class Propal extends CommonObject
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(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return 0; return 0;
} }
} }
else else
{ {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
else else
{ {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -2304,9 +2304,10 @@ class Commande extends CommonObject
* Delete the customer order * Delete the customer order
* *
* @param User $user User object * @param User $user User object
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <=0 if KO, >0 if OK * @return int <=0 if KO, >0 if OK
*/ */
function delete($user) function delete($user, $notrigger=0)
{ {
global $conf, $langs; global $conf, $langs;
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); 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 // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); 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); $result=$interface->run_triggers('ORDER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
}
if (! $error)
{
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -1116,9 +1116,10 @@ class Facture extends CommonObject
* Delete invoice * Delete invoice
* *
* @param int $rowid Id of invoice to delete. If empty, we delete current instance of 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 * @return int <0 if KO, >0 if OK
*/ */
function delete($rowid=0) function delete($rowid, $notrigger=0)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
@ -1175,6 +1176,8 @@ class Facture extends CommonObject
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{
if (! $notrigger)
{ {
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@ -1182,6 +1185,7 @@ class Facture extends CommonObject
$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); $result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
}
$this->db->commit(); $this->db->commit();
return 1; return 1;