Fix: start triggers before delete objects
This commit is contained in:
parent
195142862c
commit
c3e245d24e
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
|
||||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
|
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
||||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||||
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
|
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -1788,74 +1788,86 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
|
if (! $error && ! $notrigger)
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
|
// Call triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf);
|
||||||
|
if ($result < 0) {
|
||||||
|
$error++; $this->errors=$interface->errors;
|
||||||
|
}
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
// Delete linked object
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
|
||||||
$res = $this->deleteObjectLinked();
|
if ($this->db->query($sql))
|
||||||
if ($res < 0) $error++;
|
|
||||||
|
|
||||||
// Delete linked contacts
|
|
||||||
$res = $this->delete_linked_contact();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
|
|
||||||
if (! $error)
|
|
||||||
{
|
{
|
||||||
// We remove directory
|
// Delete linked object
|
||||||
$propalref = dol_sanitizeFileName($this->ref);
|
$res = $this->deleteObjectLinked();
|
||||||
if ($conf->propale->dir_output)
|
if ($res < 0) $error++;
|
||||||
{
|
|
||||||
$dir = $conf->propale->dir_output . "/" . $propalref ;
|
|
||||||
$file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
|
|
||||||
if (file_exists($file))
|
|
||||||
{
|
|
||||||
dol_delete_preview($this);
|
|
||||||
|
|
||||||
if (!dol_delete_file($file))
|
// Delete linked contacts
|
||||||
{
|
$res = $this->delete_linked_contact();
|
||||||
$this->error='ErrorFailToDeleteFile';
|
if ($res < 0) $error++;
|
||||||
$this->db->rollback();
|
|
||||||
return 0;
|
if (! $error)
|
||||||
}
|
{
|
||||||
}
|
// We remove directory
|
||||||
if (file_exists($dir))
|
$propalref = dol_sanitizeFileName($this->ref);
|
||||||
|
if ($conf->propale->dir_output)
|
||||||
{
|
{
|
||||||
$res=@dol_delete_dir($dir);
|
$dir = $conf->propale->dir_output . "/" . $propalref ;
|
||||||
if (! $res)
|
$file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
|
||||||
|
if (file_exists($file))
|
||||||
{
|
{
|
||||||
$this->error='ErrorFailToDeleteDir';
|
dol_delete_preview($this);
|
||||||
$this->db->rollback();
|
|
||||||
return 0;
|
if (!dol_delete_file($file))
|
||||||
|
{
|
||||||
|
$this->error='ErrorFailToDeleteFile';
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file_exists($dir))
|
||||||
|
{
|
||||||
|
$res=@dol_delete_dir($dir);
|
||||||
|
if (! $res)
|
||||||
|
{
|
||||||
|
$this->error='ErrorFailToDeleteDir';
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error && ! $notrigger)
|
if (! $error)
|
||||||
{
|
{
|
||||||
// Call triggers
|
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
$this->db->commit();
|
||||||
$interface=new Interfaces($this->db);
|
return 1;
|
||||||
$result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf);
|
}
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
else
|
||||||
// End call triggers
|
{
|
||||||
}
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||||
if (! $error)
|
$this->db->rollback();
|
||||||
{
|
return 0;
|
||||||
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
|
}
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1869,8 +1881,8 @@ class Propal extends CommonObject
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||||
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
|
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
|
||||||
@ -2316,68 +2316,73 @@ 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;
|
|
||||||
dol_syslog("Commande::delete sql=".$sql);
|
|
||||||
if (! $this->db->query($sql) )
|
|
||||||
{
|
|
||||||
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(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
|
|
||||||
if (! $this->db->query($sql) )
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::delete error", LOG_ERR);
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete linked object
|
|
||||||
$res = $this->deleteObjectLinked();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
|
|
||||||
// Delete linked contacts
|
|
||||||
$res = $this->delete_linked_contact();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
|
|
||||||
// On efface le repertoire de pdf provisoire
|
|
||||||
$comref = dol_sanitizeFileName($this->ref);
|
|
||||||
if ($conf->commande->dir_output)
|
|
||||||
{
|
|
||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
|
||||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
|
||||||
if (file_exists($file)) // We must delete all files before deleting directory
|
|
||||||
{
|
|
||||||
dol_delete_preview($this);
|
|
||||||
|
|
||||||
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 (! $error && ! $notrigger)
|
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");
|
||||||
$interface=new Interfaces($this->db);
|
$interface=new Interfaces($this->db);
|
||||||
$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) {
|
||||||
// Fin appel triggers
|
$error++; $this->errors=$interface->errors;
|
||||||
|
}
|
||||||
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// 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(get_class($this)."::delete error", LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete order
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
|
||||||
|
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
|
||||||
|
if (! $this->db->query($sql) )
|
||||||
|
{
|
||||||
|
dol_syslog(get_class($this)."::delete error", LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete linked object
|
||||||
|
$res = $this->deleteObjectLinked();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
|
||||||
|
// Delete linked contacts
|
||||||
|
$res = $this->delete_linked_contact();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
|
||||||
|
// On efface le repertoire de pdf provisoire
|
||||||
|
$comref = dol_sanitizeFileName($this->ref);
|
||||||
|
if ($conf->commande->dir_output)
|
||||||
|
{
|
||||||
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||||
|
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||||
|
if (file_exists($file)) // We must delete all files before deleting directory
|
||||||
|
{
|
||||||
|
dol_delete_preview($this);
|
||||||
|
|
||||||
|
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 (! $error)
|
if (! $error)
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
||||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||||
@ -1132,9 +1132,24 @@ class Facture extends CommonObject
|
|||||||
$error=0;
|
$error=0;
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Delete linked object
|
if (! $error && ! $notrigger)
|
||||||
$res = $this->deleteObjectLinked();
|
{
|
||||||
if ($res < 0) $error++;
|
// 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 (! $error)
|
||||||
|
{
|
||||||
|
// Delete linked object
|
||||||
|
$res = $this->deleteObjectLinked();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -1177,16 +1192,6 @@ class Facture extends CommonObject
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
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();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user