Fix: Function delete_preview is stored into correct library
This commit is contained in:
parent
4d8bd95722
commit
fd2b3099cf
@ -2322,16 +2322,16 @@ class Commande extends CommonObject
|
|||||||
dol_syslog("CustomerOrder::delete error", LOG_ERR);
|
dol_syslog("CustomerOrder::delete error", LOG_ERR);
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On efface le repertoire de pdf provisoire
|
// On efface le repertoire de pdf provisoire
|
||||||
$comref = dol_sanitizeFileName($this->ref);
|
$comref = dol_sanitizeFileName($this->ref);
|
||||||
if ($conf->commande->dir_output)
|
if ($conf->commande->dir_output)
|
||||||
{
|
{
|
||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
||||||
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
|
||||||
if (file_exists($file))
|
if (file_exists($file)) // We must delete all files before deleting directory
|
||||||
{
|
{
|
||||||
commande_delete_preview($this->db, $this->id, $this->ref);
|
dol_delete_preview($object);
|
||||||
|
|
||||||
if (!dol_delete_file($file))
|
if (!dol_delete_file($file))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1609,7 +1609,7 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions
|
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions
|
||||||
@ -1619,6 +1619,7 @@ abstract class CommonObject
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Enter description here ...
|
* Enter description here ...
|
||||||
|
*
|
||||||
* @param unknown_type $objectid
|
* @param unknown_type $objectid
|
||||||
* @param unknown_type $objecttype
|
* @param unknown_type $objecttype
|
||||||
* @param unknown_type $withpicto
|
* @param unknown_type $withpicto
|
||||||
|
|||||||
@ -201,8 +201,10 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
|
|||||||
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
|
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
|
||||||
{
|
{
|
||||||
$outputlangs->charset_output=$sav_charset_output;
|
$outputlangs->charset_output=$sav_charset_output;
|
||||||
// on supprime l'image correspondant au preview
|
|
||||||
commande_delete_preview($db, $object->id);
|
// we delete preview files
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||||
|
dol_delete_preview($object);
|
||||||
|
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
@ -234,58 +236,4 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Supprime l'image de previsualitation, pour le cas de regeneration de commande
|
|
||||||
* @param db data base object
|
|
||||||
* @param commandeid id de la commande a effacer
|
|
||||||
* @param commanderef reference de la commande si besoin
|
|
||||||
*/
|
|
||||||
function commande_delete_preview($db, $commandeid, $commanderef='')
|
|
||||||
{
|
|
||||||
global $langs,$conf;
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
|
||||||
|
|
||||||
if (!$commanderef)
|
|
||||||
{
|
|
||||||
$com = new Commande($db);
|
|
||||||
$com->fetch($commandeid);
|
|
||||||
$commanderef = $com->ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($conf->commande->dir_output)
|
|
||||||
{
|
|
||||||
$comref = dol_sanitizeFileName($commanderef);
|
|
||||||
$dir = $conf->commande->dir_output . "/" . $comref ;
|
|
||||||
$file = $dir . "/" . $comref . ".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;
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -605,6 +605,7 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a file or several files with a mask
|
* Remove a file or several files with a mask
|
||||||
|
*
|
||||||
* @param file File to delete or mask of file to delete
|
* @param file File to delete or mask of file to delete
|
||||||
* @param disableglob Disable usage of glob like *
|
* @param disableglob Disable usage of glob like *
|
||||||
* @param nophperrors Disable all PHP output errors
|
* @param nophperrors Disable all PHP output errors
|
||||||
@ -658,6 +659,7 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0,$trigg
|
|||||||
/**
|
/**
|
||||||
* Remove a directory (not recursive, so content must be empty).
|
* Remove a directory (not recursive, so content must be empty).
|
||||||
* If directory is not empty, return false
|
* If directory is not empty, return false
|
||||||
|
*
|
||||||
* @param dir Directory to delete
|
* @param dir Directory to delete
|
||||||
* @param nophperrors Disable all PHP output errors
|
* @param nophperrors Disable all PHP output errors
|
||||||
* @return boolean True if success, false if error
|
* @return boolean True if success, false if error
|
||||||
@ -712,6 +714,54 @@ function dol_delete_dir_recursive($dir,$count=0,$nophperrors=0)
|
|||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all preview files linked to object instance
|
||||||
|
*
|
||||||
|
* @param Object $object Object to clean
|
||||||
|
* @return int 0 if error, 1 if OK
|
||||||
|
*/
|
||||||
|
function dol_delete_preview($object)
|
||||||
|
{
|
||||||
|
global $langs,$conf;
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||||
|
|
||||||
|
if ($object->element == 'commande') $dir = $conf->commande->dir_output;
|
||||||
|
if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';
|
||||||
|
|
||||||
|
$refsan = dol_sanitizeFileName($object->ref);
|
||||||
|
$dir = $dir . "/" . $refsan ;
|
||||||
|
$file = $dir . "/" . $refsan . ".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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and save an upload file (for example after submitting a new file a mail form).
|
* Get and save an upload file (for example after submitting a new file a mail form).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user