Fix: les apercus en PNG n'était pas supprimé si il y avait plusieurs pages

This commit is contained in:
Regis Houssin 2006-06-09 14:58:53 +00:00
parent 4dbe1334fe
commit 7ae375b291
4 changed files with 66 additions and 27 deletions

View File

@ -182,7 +182,7 @@ class Commande
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
if (file_exists($file)) if (file_exists($file))
{ {
commande_delete_preview($this->db, $this->id); commande_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file)) if (!dol_delete_file($file))
{ {

View File

@ -211,7 +211,12 @@ function commande_pdf_create($db, $id, $modele='', $outputlangs='')
} }
} }
/**
\brief Supprime l'image de prévisualitation, pour le cas de régénération de commande
\param db objet base de donnée
\param commandeid id de la commande à effacer
\param commanderef référence de la commande si besoin
*/
function commande_delete_preview($db, $commandeid, $commanderef='') function commande_delete_preview($db, $commandeid, $commanderef='')
{ {
global $langs,$conf; global $langs,$conf;
@ -222,8 +227,6 @@ function commande_delete_preview($db, $commandeid, $commanderef='')
$com->fetch($commandeid); $com->fetch($commandeid);
$commanderef = $com->ref; $commanderef = $com->ref;
} }
//$client = new Societe($db);
//$client->fetch($com->soc_id);
if ($conf->commande->dir_output) if ($conf->commande->dir_output)
{ {

View File

@ -194,22 +194,36 @@ function propale_pdf_create($db, $id, $modele='', $outputlangs='')
\brief Supprime l'image de prévisualitation, pour le cas de régénération de propal \brief Supprime l'image de prévisualitation, pour le cas de régénération de propal
\param db objet base de donnée \param db objet base de donnée
\param propalid id de la propal à effacer \param propalid id de la propal à effacer
\param propalref référence de la propal si besoin
*/ */
function propale_delete_preview($db, $propalid) function propale_delete_preview($db, $propalid, $propalref='')
{ {
global $langs,$conf; global $langs,$conf;
if (!$propalref)
{
$propal = new Propal($db,"",$propalid); $propal = new Propal($db,"",$propalid);
$propal->fetch($propalid); $propal->fetch($propalid);
$propal->fetch_client(); $propalref = $propal->ref;
}
if ($conf->propal->dir_output) if ($conf->propal->dir_output)
{ {
$propalref = sanitize_string($propal->ref); $propref = sanitize_string($propalref);
$dir = $conf->propal->dir_output . "/" . $propalref ; $dir = $conf->propal->dir_output . "/" . $propalref ;
$file = $dir . "/" . $propalref . ".pdf.png"; $file = $dir . "/" . $propalref . ".pdf.png";
$multiple = $file . "."; $multiple = $file . ".";
if ( file_exists( $file ) && is_writable( $file ) )
{
if ( ! unlink($file) )
{
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
return 0;
}
}
else
{
for ($i = 0; $i < 20; $i++) for ($i = 0; $i < 20; $i++)
{ {
$preview = $multiple.$i; $preview = $multiple.$i;
@ -222,13 +236,6 @@ function propale_delete_preview($db, $propalid)
return 0; return 0;
} }
} }
else if ( file_exists( $file ) && is_writable( $file ) )
{
if ( ! unlink($file) )
{
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
return 0;
}
} }
} }
} }

View File

@ -1478,12 +1478,41 @@ class Propal
*/ */
function delete($user) function delete($user)
{ {
global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id;
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
// On efface le répertoire du pdf
$propalref = sanitize_string($this->ref);
if ($conf->propal->dir_output)
{
$dir = $conf->propal->dir_output . "/" . $propalref ;
$file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
if (file_exists($file))
{
propale_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (file_exists($dir))
{
if (!dol_delete_dir($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
}
}
dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)"); dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)");
return 1; return 1;
} }