fix better delete management (include extrafield too)
This commit is contained in:
parent
4e5e499ddd
commit
62c361dc1a
@ -1081,53 +1081,82 @@ class ExpenseReport extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function delete(User $fuser = null)
|
public function delete(User $fuser = null)
|
||||||
{
|
{
|
||||||
global $user, $langs, $conf;
|
global $user, $langs, $conf;
|
||||||
|
|
||||||
$rowid = $this->id;
|
$error = 0;
|
||||||
|
|
||||||
$error = 0;
|
$this->db->begin();
|
||||||
|
|
||||||
// Delete lines
|
if (!$rowid) $rowid = $this->id;
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid;
|
|
||||||
if (!$error && !$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$this->error = $this->db->error()." sql=".$sql;
|
|
||||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete llx_ecm_files
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid;
|
||||||
if (!$error) {
|
if ($this->db->query($sql)) {
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? '' : '@'.$this->module))."' AND src_object_id = ".$this->id;
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid;
|
||||||
$resql = $this->db->query($sql);
|
$resql = ;
|
||||||
if (!$resql)
|
if ($this->db->query($sql)) {
|
||||||
{
|
|
||||||
$this->error = $this->db->lasterror();
|
|
||||||
$this->errors[] = $this->error;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete main record
|
// Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
|
||||||
if (!$error) {
|
$this->deleteEcmFiles();
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid;
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if (!$resql)
|
|
||||||
{
|
|
||||||
$this->error = $this->db->error()." sql=".$sql;
|
|
||||||
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit or rollback
|
// We remove directory
|
||||||
if ($error) {
|
$ref = dol_sanitizeFileName($this->ref);
|
||||||
$this->db->rollback();
|
if ($conf->expensereport->multidir_output[$this->entity] && !empty($this->ref)) {
|
||||||
return -1;
|
$dir = $conf->expensereport->multidir_output[$this->entity]."/".$ref;
|
||||||
} else {
|
$file = $dir."/".$ref.".pdf";
|
||||||
$this->db->commit();
|
if (file_exists($file)) {
|
||||||
return 1;
|
dol_delete_preview($this);
|
||||||
}
|
|
||||||
}
|
if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
|
||||||
|
{
|
||||||
|
$this->error = 'ErrorFailToDeleteFile';
|
||||||
|
$this->errors = array('ErrorFailToDeleteFile');
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file_exists($dir)) {
|
||||||
|
$res = @dol_delete_dir_recursive($dir);
|
||||||
|
if (!$res) {
|
||||||
|
$this->error = 'ErrorFailToDeleteDir';
|
||||||
|
$this->errors = array('ErrorFailToDeleteDir');
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removed extrafields
|
||||||
|
if (!$error) {
|
||||||
|
$result = $this->deleteExtraFields();
|
||||||
|
if ($result < 0) {
|
||||||
|
$error++;
|
||||||
|
$errorflag = -4;
|
||||||
|
dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error) {
|
||||||
|
dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error = $this->db->error()." sql=".$sql;
|
||||||
|
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||||
|
$this->db->rollback();
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error = $this->db->error()." sql=".$sql;
|
||||||
|
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
|
||||||
|
$this->db->rollback();
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to status validate
|
* Set to status validate
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user