Fix: delete pdf if supplier invoice is deleted

Fix: compatibility with external modules
(minimum for 3.2)
This commit is contained in:
Regis Houssin 2012-08-05 18:29:02 +02:00
parent b1f3dbd45e
commit bb74a63d59
4 changed files with 74 additions and 26 deletions

View File

@ -77,7 +77,7 @@ class FileUpload
elseif ($element == 'order_supplier') {
$pathname = 'fourn'; $filename='fournisseur.commande';
$dir_output=$conf->fournisseur->commande->dir_output;
}
}
elseif ($element == 'invoice_supplier') {
$pathname = 'fourn'; $filename='fournisseur.facture';
$dir_output=$conf->fournisseur->facture->dir_output;
@ -100,10 +100,15 @@ class FileUpload
$object->fetch($fk_element);
$object->fetch_thirdparty();
$object_ref = dol_sanitizeFileName($object->ref);
if ($element == 'invoice_supplier') {
$object_ref = get_exdir($object->id, 2) . $object_ref;
}
$this->_options = array(
'script_url' => $_SERVER['PHP_SELF'],
'upload_dir' => $dir_output . '/' . $object->ref . '/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/',
'upload_dir' => $dir_output . '/' . $object_ref . '/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/',
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
@ -136,8 +141,8 @@ class FileUpload
),
*/
'thumbnail' => array(
'upload_dir' => $dir_output . '/' . $object->ref . '/thumbs/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/thumbs/',
'upload_dir' => $dir_output . '/' . $object_ref . '/thumbs/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/thumbs/',
'max_width' => 80,
'max_height' => 80
)

View File

@ -582,34 +582,73 @@ class FactureFournisseur extends Facture
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
dol_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid;
dol_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG);
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
$resql2 = $this->db->query($sql);
if (! $resql2) $error++;
if (! $resql2) {
$error++;
}
}
else {
$error++;
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR);
return -1;
}
if (! $error)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('INVOICE_SUPPLIER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
if (! $error)
{
// We remove directory
if ($conf->fournisseur->facture->dir_output)
{
$ref = dol_sanitizeFileName($this->ref);
$dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2).$ref;
$file = $dir . "/" . $ref . ".pdf";
if (file_exists($file))
{
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
$this->error='ErrorFailToDeleteFile';
$error++;
}
}
if (file_exists($dir))
{
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->error='ErrorFailToDeleteDir';
$error++;
}
}
}
}
if (! $error)
{
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR);
return -1;
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -$error;
}
}

View File

@ -119,11 +119,12 @@ if ($action=='delete')
if ($facture->fetch($facid))
{
$langs->load("other");
$facture->fetch_thirdparty();
$ref=dol_sanitizeFileName($facture->ref);
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facture->id,2).$ref;
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file);
dol_delete_file($file,0,0,0,$facture);
$mesg = '<div class="ok">'.$langs->trans('FileWasRemoved',GETPOST('urlfile')).'</div>';
}
}

View File

@ -119,6 +119,7 @@ elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fourni
elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
{
$object->fetch($id);
$object->fetch_thirdparty();
$result=$object->delete($id);
if ($result > 0)
{
@ -791,6 +792,7 @@ elseif ($action == 'builddoc')
{
// Save modele used
$object->fetch($id);
$object->fetch_thirdparty();
if ($_REQUEST['model'])
{
$object->setDocModel($user, $_REQUEST['model']);
@ -822,9 +824,10 @@ elseif ($action == 'remove_file')
if ($object->fetch($id))
{
$object->fetch_thirdparty();
$upload_dir = $conf->fournisseur->facture->dir_output . "/";
$file = $upload_dir . '/' . GETPOST('file');
dol_delete_file($file);
dol_delete_file($file,0,0,0,$object);
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
}
}