mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-22 01:11:21 +01:00
Qual: Mutualize code to delete previews
This commit is contained in:
@@ -1763,7 +1763,7 @@ class Propal extends CommonObject
|
||||
$file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
|
||||
if (file_exists($file))
|
||||
{
|
||||
propale_delete_preview($this->db, $this->id, $this->ref);
|
||||
dol_delete_preview($this);
|
||||
|
||||
if (!dol_delete_file($file))
|
||||
{
|
||||
|
||||
@@ -2342,7 +2342,7 @@ class Commande extends CommonObject
|
||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||
if (file_exists($file)) // We must delete all files before deleting directory
|
||||
{
|
||||
dol_delete_preview($object);
|
||||
dol_delete_preview($this);
|
||||
|
||||
if (!dol_delete_file($file))
|
||||
{
|
||||
|
||||
@@ -727,6 +727,14 @@ function dol_delete_preview($object)
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
if ($object->element == 'commande') $dir = $conf->commande->dir_output;
|
||||
elseif ($object->element == 'propal') $dir = $conf->propale->dir_output;
|
||||
elseif ($object->element == 'ficheinter') $dir = $conf->ficheinter->dir_output;
|
||||
elseif ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande';
|
||||
elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture';
|
||||
elseif ($object->element == 'project') $dir = $conf->projet->dir_output;
|
||||
elseif ($object->element == 'delivery') $dir = $conf->livraison->dir_output;
|
||||
elseif ($object->element == 'facture') $dir = $conf->facture->dir_output;
|
||||
elseif ($object->element == 'don') $dir = $conf->don->dir_output;
|
||||
if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';
|
||||
|
||||
$refsan = dol_sanitizeFileName($object->ref);
|
||||
@@ -762,6 +770,58 @@ function dol_delete_preview($object)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a meta file with document file into same directory.
|
||||
* This should allow rgrep search
|
||||
*
|
||||
* @param Object $object Object
|
||||
* @return void
|
||||
*/
|
||||
function dol_meta_create($object)
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$object->fetch_thirdparty();
|
||||
|
||||
if ($conf->facture->dir_output)
|
||||
{
|
||||
$facref = dol_sanitizeFileName($object->ref);
|
||||
$dir = $conf->facture->dir_output . "/" . $facref ;
|
||||
$file = $dir . "/" . $facref . ".meta";
|
||||
|
||||
if (! is_dir($dir))
|
||||
{
|
||||
create_exdir($dir);
|
||||
}
|
||||
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$nblignes = count($object->lines);
|
||||
$client = $object->client->nom . " " . $object->client->address . " " . $object->client->cp . " " . $object->client->ville;
|
||||
$meta = "REFERENCE=\"" . $object->ref . "\"
|
||||
DATE=\"" . dol_print_date($object->date,'') . "\"
|
||||
NB_ITEMS=\"" . $nblignes . "\"
|
||||
CLIENT=\"" . $client . "\"
|
||||
TOTAL_HT=\"" . $object->total_ht . "\"
|
||||
TOTAL_TTC=\"" . $object->total_ttc . "\"\n";
|
||||
|
||||
for ($i = 0 ; $i < $nblignes ; $i++)
|
||||
{
|
||||
//Pour les articles
|
||||
$meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\"
|
||||
ITEM_" . $i . "_UNIT_PRICE=\"" . $object->lines[$i]->price . "\"
|
||||
ITEM_" . $i . "_TVA=\"" .$object->lines[$i]->tva_tx . "\"
|
||||
ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($object->lines[$i]->desc)) . "\"
|
||||
";
|
||||
}
|
||||
}
|
||||
$fp = fopen($file,"w");
|
||||
fputs($fp,$meta);
|
||||
fclose($fp);
|
||||
if (! empty($conf->global->MAIN_UMASK))
|
||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and save an upload file (for example after submitting a new file a mail form).
|
||||
|
||||
@@ -173,12 +173,11 @@ function don_create($db, $id, $message, $modele, $outputlangs)
|
||||
$sav_charset_output=$outputlangs->charset_output;
|
||||
if ($obj->write_file($id,$outputlangs) > 0)
|
||||
{
|
||||
// Success. We build meta file
|
||||
don_meta_create($db, $id);
|
||||
// et on supprime l'image correspondant au preview
|
||||
don_delete_preview($db, $id);
|
||||
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -196,34 +195,4 @@ function don_create($db, $id, $message, $modele, $outputlangs)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Cree un meta fichier a cote de la facture sur le disque pour faciliter les recherches en texte plein. Pourquoi ? tout simplement parcequ'en fin d'exercice quand je suis avec mon comptable je n'ai pas de connexion internet "rapide" pour retrouver en 2 secondes une facture non pay<61>e ou compliqu<71>e <20> g<>rer ... avec un rgrep c'est vite fait bien fait [eric seigne
|
||||
* \param db Objet base de donnee
|
||||
* \param donid Id du don a creer
|
||||
* \param message Message
|
||||
*/
|
||||
function don_meta_create($db, $donid, $message="")
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$don = new Don($db);
|
||||
$don->id=$donid;
|
||||
$don->fetch($donid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Supprime l'image de previsualitation, pour le cas de r<>g<EFBFBD>n<EFBFBD>ration de facture
|
||||
* \param db Objet base de donnee
|
||||
* \param donid Id du don
|
||||
*/
|
||||
function don_delete_preview($db, $donid)
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$don = new Don($db);
|
||||
$don->id=$donid;
|
||||
$don->fetch($donid);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -116,8 +116,10 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs)
|
||||
if ($obj->write_file($object, $outputlangs) > 0)
|
||||
{
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
// on supprime l'image correspondant au preview
|
||||
//expedition_delete_preview($db, $id);
|
||||
|
||||
// we delete preview files
|
||||
//require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
//dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -209,13 +209,15 @@ function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hide
|
||||
$sav_charset_output=$outputlangs->charset_output;
|
||||
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
|
||||
{
|
||||
// Success in building document. We build meta file.
|
||||
facture_meta_create($db, $object->id);
|
||||
// et on supprime l'image correspondant au preview
|
||||
facture_delete_preview($db, $object->id);
|
||||
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// We delete old preview
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
|
||||
// Success in building document. We build meta file.
|
||||
dol_meta_create($object);
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
$interface=new Interfaces($db);
|
||||
@@ -240,93 +242,4 @@ function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hide
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a meta file with document file into same directory.
|
||||
* This should allow rgrep search
|
||||
*
|
||||
* @param db Objet base de donnee
|
||||
* @param facid Id de la facture a creer
|
||||
* @param message Message
|
||||
*/
|
||||
function facture_meta_create($db, $facid, $message="")
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
$fac = new Facture($db);
|
||||
$fac->fetch($facid);
|
||||
$fac->fetch_thirdparty();
|
||||
|
||||
if ($conf->facture->dir_output)
|
||||
{
|
||||
$facref = dol_sanitizeFileName($fac->ref);
|
||||
$dir = $conf->facture->dir_output . "/" . $facref ;
|
||||
$file = $dir . "/" . $facref . ".meta";
|
||||
|
||||
if (! is_dir($dir))
|
||||
{
|
||||
create_exdir($dir);
|
||||
}
|
||||
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$nblignes = count($fac->lines);
|
||||
$client = $fac->client->nom . " " . $fac->client->address . " " . $fac->client->cp . " " . $fac->client->ville;
|
||||
$meta = "REFERENCE=\"" . $fac->ref . "\"
|
||||
DATE=\"" . dol_print_date($fac->date,'') . "\"
|
||||
NB_ITEMS=\"" . $nblignes . "\"
|
||||
CLIENT=\"" . $client . "\"
|
||||
TOTAL_HT=\"" . $fac->total_ht . "\"
|
||||
TOTAL_TTC=\"" . $fac->total_ttc . "\"\n";
|
||||
|
||||
for ($i = 0 ; $i < $nblignes ; $i++)
|
||||
{
|
||||
//Pour les articles
|
||||
$meta .= "ITEM_" . $i . "_QUANTITY=\"" . $fac->lines[$i]->qty . "\"
|
||||
ITEM_" . $i . "_UNIT_PRICE=\"" . $fac->lines[$i]->price . "\"
|
||||
ITEM_" . $i . "_TVA=\"" .$fac->lines[$i]->tva_tx . "\"
|
||||
ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($fac->lines[$i]->desc)) . "\"
|
||||
";
|
||||
}
|
||||
}
|
||||
$fp = fopen($file,"w");
|
||||
fputs($fp,$meta);
|
||||
fclose($fp);
|
||||
if (! empty($conf->global->MAIN_UMASK))
|
||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Supprime l'image de previsualitation, pour le cas de regeneration de facture
|
||||
*
|
||||
* @param db objet base de donnee
|
||||
* @param facid id de la facture a creer
|
||||
*/
|
||||
function facture_delete_preview($db, $facid)
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
$fac = new Facture($db);
|
||||
$fac->fetch($facid);
|
||||
|
||||
if ($conf->facture->dir_output)
|
||||
{
|
||||
$facref = dol_sanitizeFileName($fac->ref);
|
||||
$dir = $conf->facture->dir_output . "/" . $facref ;
|
||||
$file = $dir . "/" . $facref . ".pdf.png";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file,1) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -197,57 +197,4 @@ function fichinter_create($db, $object, $modele='', $outputlangs='')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the image preview, in case of regeneration
|
||||
* @param db database object
|
||||
* @param fichinterid id to delete
|
||||
* @param fichinterref reference if needed
|
||||
*/
|
||||
function fichinter_delete_preview($db, $fichinterid, $fichinterref='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
if (!$fichinterref)
|
||||
{
|
||||
$fichinter = new Fichinter($db);
|
||||
$fichinter->fetch($fichinterid);
|
||||
$fichinterref = $fichinter->ref;
|
||||
}
|
||||
|
||||
if ($conf->ficheinter->dir_output)
|
||||
{
|
||||
$fichinterref = dol_sanitizeFileName($fichinterref);
|
||||
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
|
||||
$file = $dir . "/" . $fichinterref . ".pdf.png";
|
||||
$multiple = $file . ".";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($i = 0; $i < 20; $i++)
|
||||
{
|
||||
$preview = $multiple.$i;
|
||||
if ( file_exists( $preview ) && is_writable( $preview ) )
|
||||
{
|
||||
if ( ! dol_delete_file($preview,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -172,10 +172,11 @@ function delivery_order_pdf_create($db, $object, $model='', $outputlangs='')
|
||||
$sav_charset_output=$outputlangs->charset_output;
|
||||
if ($obj->write_file($object,$outputlangs) > 0)
|
||||
{
|
||||
// on supprime l'image correspondant au preview
|
||||
delivery_order_delete_preview($db, $object->id);
|
||||
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -193,33 +194,4 @@ function delivery_order_pdf_create($db, $object, $model='', $outputlangs='')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function delivery_order_delete_preview($db, $deliveryid)
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
$delivery = new Livraison($db,"",$deliveryid);
|
||||
$delivery->fetch($deliveryid);
|
||||
$client = new Societe($db);
|
||||
$client->fetch($delivery->socid);
|
||||
|
||||
if ($conf->livraison->dir_output)
|
||||
{
|
||||
$deliveryref = dol_sanitizeFileName($delivery->ref);
|
||||
$dir = $conf->livraison->dir_output . "/" . $deliveryref ;
|
||||
$file = $dir . "/" . $deliveryref . ".pdf.png";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -174,10 +174,11 @@ function project_pdf_create($db, $object, $model,$outputlangs)
|
||||
$sav_charset_output=$outputlangs->charset_output;
|
||||
if ($obj->write_file($object,$outputlangs) > 0)
|
||||
{
|
||||
// on supprime l'image correspondant au preview
|
||||
project_delete_preview($db, $object->id);
|
||||
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -195,39 +196,4 @@ function project_pdf_create($db, $object, $model,$outputlangs)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param $db
|
||||
* @param $objectid
|
||||
* @return int
|
||||
*/
|
||||
function project_delete_preview($db, $objectid)
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
$project = new Project($db);
|
||||
$project->fetch($objectid);
|
||||
$client = new Societe($db);
|
||||
$client->fetch($project->socid);
|
||||
|
||||
if ($conf->projet->dir_output.'/commande')
|
||||
{
|
||||
$projectRef = dol_sanitizeFileName($project->ref);
|
||||
$dir = $conf->projet->dir_output . "/" . $projectRef ;
|
||||
$file = $dir . "/" . $projectRef . ".pdf.png";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -205,8 +205,10 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
|
||||
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
|
||||
{
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
// on supprime l'image correspondant au preview
|
||||
propale_delete_preview($db, $object->id);
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
@@ -239,57 +241,4 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete preview files
|
||||
* @param db objet base de donnee
|
||||
* @param propalid id de la propal a effacer
|
||||
* @param propalref reference de la propal si besoin
|
||||
*/
|
||||
function propale_delete_preview($db, $propalid, $propalref='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
if (!$propalref)
|
||||
{
|
||||
$propal = new Propal($db,"",$propalid);
|
||||
$propal->fetch($propalid);
|
||||
$propalref = $propal->ref;
|
||||
}
|
||||
|
||||
if ($conf->propale->dir_output)
|
||||
{
|
||||
$propalref = dol_sanitizeFileName($propalref);
|
||||
$dir = $conf->propale->dir_output . "/" . $propalref ;
|
||||
$file = $dir . "/" . $propalref . ".pdf.png";
|
||||
$multiple = $file . ".";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($i = 0; $i < 20; $i++)
|
||||
{
|
||||
$preview = $multiple.$i;
|
||||
|
||||
if ( file_exists( $preview ) && is_writable( $preview ) )
|
||||
{
|
||||
if ( ! unlink($preview) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -98,10 +98,11 @@ function supplier_invoice_pdf_create($db, $object, $model, $outputlangs)
|
||||
$sav_charset_output=$outputlangs->charset_output;
|
||||
if ($obj->write_file($object,$outputlangs) > 0)
|
||||
{
|
||||
// on supprime l'image correspondant au preview
|
||||
supplier_invoice_delete_preview($db, $object->id);
|
||||
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -119,38 +120,4 @@ function supplier_invoice_pdf_create($db, $object, $model, $outputlangs)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete preview files
|
||||
* @param $db
|
||||
* @param $objectid
|
||||
* @return int
|
||||
*/
|
||||
function supplier_invoice_delete_preview($db, $objectid)
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
$comfourn = new FactureFournisseur($db);
|
||||
$comfourn->fetch($objectid);
|
||||
$client = new Societe($db);
|
||||
$client->fetch($comfourn->socid);
|
||||
|
||||
if ($conf->fournisseur->dir_output.'/facture')
|
||||
{
|
||||
$comfournref = dol_sanitizeFileName($comfourn->ref);
|
||||
$dir = $conf->facture->dir_output . "/" . $comfournref ;
|
||||
$file = $dir . "/" . $comfournref . ".pdf.png";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -199,8 +199,10 @@ function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedeta
|
||||
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0)
|
||||
{
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
// on supprime l'image correspondant au preview
|
||||
supplier_order_delete_preview($db, $object->id);
|
||||
|
||||
// we delete preview files
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
dol_delete_preview($object);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -225,62 +227,4 @@ function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedeta
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete preview files, pour le cas de regeneration de commande
|
||||
* @param $db data base object
|
||||
* @param $comfournid id de la commande a effacer
|
||||
* @param $comfournref reference de la commande si besoin
|
||||
* @return int
|
||||
*/
|
||||
function supplier_order_delete_preview($db, $comfournid, $comfournref='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||
|
||||
if (!$comfournref)
|
||||
{
|
||||
$comfourn = new CommandeFournisseur($db,"",$comfournid);
|
||||
$comfourn->fetch($comfournid);
|
||||
$comfournref = $comfourn->ref;
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($comfourn->socid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($conf->fournisseur->dir_output.'/commande')
|
||||
{
|
||||
$suppordref = dol_sanitizeFileName($comfournref);
|
||||
$dir = $conf->fournisseur->dir_output . "/" . $suppordref ;
|
||||
$file = $dir . "/" . $suppordref . ".pdf.png";
|
||||
$multiple = $file . ".";
|
||||
|
||||
if ( file_exists( $file ) && is_writable( $file ) )
|
||||
{
|
||||
if ( ! dol_delete_file($file,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($i = 0; $i < 20; $i++)
|
||||
{
|
||||
$preview = $multiple.$i;
|
||||
|
||||
if ( file_exists( $preview ) && is_writable( $preview ) )
|
||||
{
|
||||
if ( ! dol_delete_file($preview,1) )
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -617,7 +617,7 @@ class Fichinter extends CommonObject
|
||||
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
|
||||
if (file_exists($file))
|
||||
{
|
||||
fichinter_delete_preview($this->db, $this->id, $this->ref);
|
||||
dol_delete_preview($this);
|
||||
|
||||
if (!dol_delete_file($file))
|
||||
{
|
||||
|
||||
@@ -438,7 +438,7 @@ class Project extends CommonObject
|
||||
$file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf";
|
||||
if (file_exists($file))
|
||||
{
|
||||
//project_delete_preview($this->db, $this->id, $this->ref);
|
||||
dol_delete_preview($this);
|
||||
|
||||
if (!dol_delete_file($file))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user