FIX #7775 Order of deletion in delete method (trigger first)
This commit is contained in:
parent
45fc5701ae
commit
bc093ef969
@ -3119,7 +3119,6 @@ class Commande extends CommonOrder
|
|||||||
// End call triggers
|
// 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)
|
if (! $error)
|
||||||
{
|
{
|
||||||
// Delete order details
|
// Delete order details
|
||||||
@ -3129,23 +3128,24 @@ class Commande extends CommonOrder
|
|||||||
$error++;
|
$error++;
|
||||||
$this->errors[]=$this->db->lasterror();
|
$this->errors[]=$this->db->lasterror();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delete order
|
if (! $error)
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
|
{
|
||||||
if (! $this->db->query($sql) )
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
$this->errors[]=$this->db->lasterror();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete linked object
|
// Delete linked object
|
||||||
$res = $this->deleteObjectLinked();
|
$res = $this->deleteObjectLinked();
|
||||||
if ($res < 0) $error++;
|
if ($res < 0) $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)
|
||||||
|
{
|
||||||
// Remove extrafields
|
// Remove extrafields
|
||||||
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
|
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);
|
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);
|
$comref = dol_sanitizeFileName($this->ref);
|
||||||
if ($conf->commande->dir_output && !empty($this->ref))
|
if ($conf->commande->dir_output && !empty($this->ref))
|
||||||
{
|
{
|
||||||
@ -3183,8 +3197,6 @@ class Commande extends CommonOrder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
|
|||||||
@ -3650,7 +3650,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
|
|||||||
|
|
||||||
$return.= "\n";
|
$return.= "\n";
|
||||||
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
|
$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.= '<td class="nobordernopadding" valign="middle">';
|
||||||
$return.= '<div class="titre">'.$titre.'</div>';
|
$return.= '<div class="titre">'.$titre.'</div>';
|
||||||
$return.= '</td>';
|
$return.= '</td>';
|
||||||
|
|||||||
@ -840,85 +840,96 @@ class Fichinter extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$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
|
// Delete linked object
|
||||||
$res = $this->deleteObjectLinked();
|
if (! $error)
|
||||||
if ($res < 0) $error++;
|
{
|
||||||
|
$res = $this->deleteObjectLinked();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete linked contacts
|
// Delete linked contacts
|
||||||
$res = $this->delete_linked_contact();
|
if (! $error)
|
||||||
if ($res < 0)
|
|
||||||
{
|
{
|
||||||
$this->error='ErrorFailToDeleteLinkedContact';
|
$res = $this->delete_linked_contact();
|
||||||
$error++;
|
if ($res < 0)
|
||||||
|
{
|
||||||
|
$this->error='ErrorFailToDeleteLinkedContact';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
|
||||||
return -1;
|
$sql.= " WHERE fk_fichinter = ".$this->id;
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (! $resql) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
|
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
|
||||||
$sql.= " WHERE fk_fichinter = ".$this->id;
|
|
||||||
|
|
||||||
dol_syslog("Fichinter::delete", LOG_DEBUG);
|
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
{
|
{
|
||||||
|
// Remove extrafields
|
||||||
|
$res = $this->deleteExtraFields();
|
||||||
|
if ($res < 0) $error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// Delete object
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
dol_syslog("Fichinter::delete", LOG_DEBUG);
|
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)
|
||||||
{
|
{
|
||||||
|
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
|
||||||
// Remove directory with files
|
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
|
||||||
$fichinterref = dol_sanitizeFileName($this->ref);
|
if (file_exists($file))
|
||||||
if ($conf->ficheinter->dir_output)
|
|
||||||
{
|
{
|
||||||
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
|
dol_delete_preview($this);
|
||||||
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
|
|
||||||
if (file_exists($file))
|
|
||||||
{
|
|
||||||
dol_delete_preview($this);
|
|
||||||
|
|
||||||
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
|
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_dir_recursive($dir))
|
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
|
||||||
{
|
return 0;
|
||||||
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (file_exists($dir))
|
||||||
if (! $notrigger)
|
|
||||||
{
|
{
|
||||||
// Call trigger
|
if (! dol_delete_dir_recursive($dir))
|
||||||
$result=$this->call_trigger('FICHINTER_DELETE',$user);
|
{
|
||||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
|
||||||
// End call triggers
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
if (! $error)
|
||||||
return 1;
|
{
|
||||||
}
|
$this->db->commit();
|
||||||
else
|
return 1;
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
$this->db->rollback();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user