Qual: Mutualize code to delete previews

This commit is contained in:
Laurent Destailleur
2011-11-04 00:27:30 +01:00
parent d872f4d389
commit c16c09a451
14 changed files with 101 additions and 412 deletions

View File

@@ -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;
}
?>