Fix code of deletion of objects
This commit is contained in:
parent
e272130a6a
commit
69b06a25e8
@ -2947,10 +2947,23 @@ class Propal extends CommonObject
|
|||||||
if (! $this->db->query($sqlef) || ! $this->db->query($sql)) {
|
if (! $this->db->query($sqlef) || ! $this->db->query($sql)) {
|
||||||
$error++;
|
$error++;
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
// Delete linked object
|
||||||
|
$res = $this->deleteObjectLinked();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
// Delete linked contacts
|
||||||
|
$res = $this->delete_linked_contact();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
// Removed extrafields of object
|
// Removed extrafields of object
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$result = $this->deleteExtraFields();
|
$result = $this->deleteExtraFields();
|
||||||
@ -2966,25 +2979,15 @@ class Propal extends CommonObject
|
|||||||
$res = $this->db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
if (! $res) {
|
if (! $res) {
|
||||||
$error++;
|
$error++;
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
// Delete linked object
|
|
||||||
$res = $this->deleteObjectLinked();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
// Delete linked contacts
|
|
||||||
$res = $this->delete_linked_contact();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete record into ECM index and physically
|
// Delete record into ECM index and physically
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$res = $this->deleteEcmFiles(); // Deleting files physically is done later with the dol_delete_dir_recursive
|
$res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
|
||||||
if (! $res) {
|
if (! $res) {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
@ -3001,7 +3004,7 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
if (!dol_delete_file($file, 0, 0, 0, $this)) {
|
if (!dol_delete_file($file, 0, 0, 0, $this)) {
|
||||||
$this->error = 'ErrorFailToDeleteFile';
|
$this->error = 'ErrorFailToDeleteFile';
|
||||||
$this->errors = array('ErrorFailToDeleteFile');
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3010,7 +3013,7 @@ class Propal extends CommonObject
|
|||||||
$res = @dol_delete_dir_recursive($dir);
|
$res = @dol_delete_dir_recursive($dir);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
$this->error = 'ErrorFailToDeleteDir';
|
$this->error = 'ErrorFailToDeleteDir';
|
||||||
$this->errors = array('ErrorFailToDeleteDir');
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3342,106 +3342,95 @@ class Commande extends CommonOrder
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (!$error && !$notrigger)
|
if (!$notrigger) {
|
||||||
{
|
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result = $this->call_trigger('ORDER_DELETE', $user);
|
$result = $this->call_trigger('ORDER_DELETE', $user);
|
||||||
if ($result < 0) $error++;
|
if ($result < 0) { $error++; }
|
||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test we can delete
|
||||||
if ($this->nb_expedition() != 0)
|
if ($this->nb_expedition() != 0)
|
||||||
{
|
{
|
||||||
$this->errors[] = $langs->trans('SomeShipmentExists');
|
$this->errors[] = $langs->trans('SomeShipmentExists');
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
// Delete extrafields of lines and lines
|
||||||
{
|
if (!$error && !empty($this->table_element_line)) {
|
||||||
// Delete extrafields of order details
|
$tabletodelete = $this->table_element_line;
|
||||||
$main = MAIN_DB_PREFIX.'commandedet';
|
$sqlef = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete."_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".$this->id.")";
|
||||||
$ef = $main."_extrafields";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".$this->id;
|
||||||
$sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")";
|
if (! $this->db->query($sqlef) || ! $this->db->query($sql)) {
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$error++;
|
$error++;
|
||||||
$this->errors[] = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
// Delete order details
|
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = ".$this->id;
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
$this->errors[] = $this->db->lasterror();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$error)
|
|
||||||
{
|
|
||||||
// Delete linked object
|
// Delete linked object
|
||||||
$res = $this->deleteObjectLinked();
|
$res = $this->deleteObjectLinked();
|
||||||
if ($res < 0) $error++;
|
if ($res < 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
// Delete linked contacts
|
// Delete linked contacts
|
||||||
$res = $this->delete_linked_contact();
|
$res = $this->delete_linked_contact();
|
||||||
if ($res < 0) $error++;
|
if ($res < 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
// Removed extrafields of object
|
||||||
{
|
if (!$error) {
|
||||||
// Remove extrafields
|
|
||||||
$result = $this->deleteExtraFields();
|
$result = $this->deleteExtraFields();
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
$error++;
|
$error++;
|
||||||
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
// Delete main record
|
||||||
{
|
if (!$error) {
|
||||||
// Delete object
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE rowid = ".$this->id;
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
|
$res = $this->db->query($sql);
|
||||||
if (!$this->db->query($sql))
|
if (! $res) {
|
||||||
{
|
|
||||||
$error++;
|
$error++;
|
||||||
$this->errors[] = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
// Delete record into ECM index and physically
|
||||||
{
|
if (!$error) {
|
||||||
// Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
|
$res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
|
||||||
$this->deleteEcmFiles();
|
if (! $res) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove directory with files
|
if (!$error) {
|
||||||
$comref = dol_sanitizeFileName($this->ref);
|
// We remove directory
|
||||||
if ($conf->commande->multidir_output[$this->entity] && !empty($this->ref))
|
$ref = dol_sanitizeFileName($this->ref);
|
||||||
{
|
if ($conf->commande->multidir_output[$this->entity] && !empty($this->ref)) {
|
||||||
$dir = $conf->commande->multidir_output[$this->entity]."/".$comref;
|
$dir = $conf->commande->multidir_output[$this->entity]."/".$ref;
|
||||||
$file = $conf->commande->multidir_output[$this->entity]."/".$comref."/".$comref.".pdf";
|
$file = $dir."/".$ref.".pdf";
|
||||||
if (file_exists($file)) // We must delete all files before deleting directory
|
if (file_exists($file)) {
|
||||||
{
|
|
||||||
dol_delete_preview($this);
|
dol_delete_preview($this);
|
||||||
|
|
||||||
if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
|
if (!dol_delete_file($file, 0, 0, 0, $this)) {
|
||||||
{
|
$this->error = 'ErrorFailToDeleteFile';
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file_exists($dir))
|
if (file_exists($dir)) {
|
||||||
{
|
$res = @dol_delete_dir_recursive($dir);
|
||||||
if (!dol_delete_dir_recursive($dir))
|
if (!$res) {
|
||||||
{
|
$this->error = 'ErrorFailToDeleteDir';
|
||||||
$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3449,17 +3438,13 @@ class Commande extends CommonOrder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
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 {
|
||||||
foreach ($this->errors as $errmsg)
|
|
||||||
{
|
|
||||||
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1 * $error;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2184,6 +2184,7 @@ class Facture extends CommonInvoice
|
|||||||
if (!$this->db->query($sql))
|
if (!$this->db->query($sql))
|
||||||
{
|
{
|
||||||
$this->error = $this->db->error()." sql=".$sql;
|
$this->error = $this->db->error()." sql=".$sql;
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
@ -2244,6 +2245,7 @@ class Facture extends CommonInvoice
|
|||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$this->error = $langs->trans("ErrorFailToDeleteFile", $file);
|
$this->error = $langs->trans("ErrorFailToDeleteFile", $file);
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2254,6 +2256,7 @@ class Facture extends CommonInvoice
|
|||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
|
$this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2264,11 +2267,13 @@ class Facture extends CommonInvoice
|
|||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror()." sql=".$sql;
|
$this->error = $this->db->lasterror()." sql=".$sql;
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror()." sql=".$sql;
|
$this->error = $this->db->lasterror()." sql=".$sql;
|
||||||
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1104,10 +1104,23 @@ class ExpenseReport extends CommonObject
|
|||||||
if (! $this->db->query($sql)) {
|
if (! $this->db->query($sql)) {
|
||||||
$error++;
|
$error++;
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
// Delete linked object
|
||||||
|
$res = $this->deleteObjectLinked();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
// Delete linked contacts
|
||||||
|
$res = $this->delete_linked_contact();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
// Removed extrafields of object
|
// Removed extrafields of object
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$result = $this->deleteExtraFields();
|
$result = $this->deleteExtraFields();
|
||||||
@ -1123,25 +1136,15 @@ class ExpenseReport extends CommonObject
|
|||||||
$res = $this->db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
if (! $res) {
|
if (! $res) {
|
||||||
$error++;
|
$error++;
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->errors[] = $this->error;
|
||||||
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
// Delete linked object
|
|
||||||
$res = $this->deleteObjectLinked();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
// Delete linked contacts
|
|
||||||
$res = $this->delete_linked_contact();
|
|
||||||
if ($res < 0) $error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete record into ECM index and physically
|
// Delete record into ECM index and physically
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
$res = $this->deleteEcmFiles(); // Deleting files physically is done later with the dol_delete_dir_recursive
|
$res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
|
||||||
if (! $res) {
|
if (! $res) {
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
@ -1150,15 +1153,15 @@ class ExpenseReport extends CommonObject
|
|||||||
if (!$error) {
|
if (!$error) {
|
||||||
// We remove directory
|
// We remove directory
|
||||||
$ref = dol_sanitizeFileName($this->ref);
|
$ref = dol_sanitizeFileName($this->ref);
|
||||||
if ($conf->propal->multidir_output[$this->entity] && !empty($this->ref)) {
|
if ($conf->expensereport->multidir_output[$this->entity] && !empty($this->ref)) {
|
||||||
$dir = $conf->propal->multidir_output[$this->entity]."/".$ref;
|
$dir = $conf->expensereport->multidir_output[$this->entity]."/".$ref;
|
||||||
$file = $dir."/".$ref.".pdf";
|
$file = $dir."/".$ref.".pdf";
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
dol_delete_preview($this);
|
dol_delete_preview($this);
|
||||||
|
|
||||||
if (!dol_delete_file($file, 0, 0, 0, $this)) {
|
if (!dol_delete_file($file, 0, 0, 0, $this)) {
|
||||||
$this->error = 'ErrorFailToDeleteFile';
|
$this->error = 'ErrorFailToDeleteFile';
|
||||||
$this->errors = array('ErrorFailToDeleteFile');
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1167,7 +1170,7 @@ class ExpenseReport extends CommonObject
|
|||||||
$res = @dol_delete_dir_recursive($dir);
|
$res = @dol_delete_dir_recursive($dir);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
$this->error = 'ErrorFailToDeleteDir';
|
$this->error = 'ErrorFailToDeleteDir';
|
||||||
$this->errors = array('ErrorFailToDeleteDir');
|
$this->errors[] = $this->error;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user