FIX #7775 Order of deletion in delete method (trigger first)

This commit is contained in:
Laurent Destailleur 2017-11-06 19:27:10 +01:00
parent 45fc5701ae
commit bc093ef969
3 changed files with 88 additions and 65 deletions

View File

@ -3119,7 +3119,6 @@ class Commande extends CommonOrder
// End call triggers
}
//TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail
if (! $error)
{
// Delete order details
@ -3129,23 +3128,24 @@ class Commande extends CommonOrder
$error++;
$this->errors[]=$this->db->lasterror();
}
}
// Delete order
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
if (! $this->db->query($sql) )
{
$error++;
$this->errors[]=$this->db->lasterror();
}
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++;
}
if (! $error)
{
// Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
@ -3156,8 +3156,22 @@ class Commande extends CommonOrder
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
}
// On efface le repertoire de pdf provisoire
if (! $error)
{
// Delete object
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
if (! $this->db->query($sql) )
{
$error++;
$this->errors[]=$this->db->lasterror();
}
}
if (! $error)
{
// Remove directory with files
$comref = dol_sanitizeFileName($this->ref);
if ($conf->commande->dir_output && !empty($this->ref))
{
@ -3183,8 +3197,6 @@ class Commande extends CommonOrder
}
}
}
}
if (! $error)

View File

@ -3650,7 +3650,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
$return.= "\n";
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle" id="pictotitle"', $pictoisfullpath).'</td>';
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
$return.= '<td class="nobordernopadding" valign="middle">';
$return.= '<div class="titre">'.$titre.'</div>';
$return.= '</td>';

View File

@ -840,85 +840,96 @@ class Fichinter extends CommonObject
$this->db->begin();
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('FICHINTER_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers
}
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
if (! $error)
{
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
}
// Delete linked contacts
$res = $this->delete_linked_contact();
if ($res < 0)
if (! $error)
{
$this->error='ErrorFailToDeleteLinkedContact';
$error++;
$res = $this->delete_linked_contact();
if ($res < 0)
{
$this->error='ErrorFailToDeleteLinkedContact';
$error++;
}
}
if ($error)
if (! $error)
{
$this->db->rollback();
return -1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
$sql.= " WHERE fk_fichinter = ".$this->id;
$resql = $this->db->query($sql);
if (! $resql) $error++;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
$sql.= " WHERE fk_fichinter = ".$this->id;
dol_syslog("Fichinter::delete", LOG_DEBUG);
if ( $this->db->query($sql) )
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
// Remove extrafields
$res = $this->deleteExtraFields();
if ($res < 0) $error++;
}
if (! $error)
{
// Delete object
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
dol_syslog("Fichinter::delete", LOG_DEBUG);
if ( $this->db->query($sql) )
$resql = $this->db->query($sql);
if (! $resql) $error++;
}
if (! $error)
{
// Remove directory with files
$fichinterref = dol_sanitizeFileName($this->ref);
if ($conf->ficheinter->dir_output)
{
// Remove directory with files
$fichinterref = dol_sanitizeFileName($this->ref);
if ($conf->ficheinter->dir_output)
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
if (file_exists($file))
{
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
if (file_exists($file))
{
dol_delete_preview($this);
dol_delete_preview($this);
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (file_exists($dir))
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (! $notrigger)
if (file_exists($dir))
{
// Call trigger
$result=$this->call_trigger('FICHINTER_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
}
}
}
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -2;
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}