diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 6105b82b1af..f921db3b26f 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -179,15 +179,24 @@ class Commande if ($conf->commande->dir_output) { $dir = $conf->commande->dir_output . "/" . $comref ; - if (file_exists($dir)) + $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; + if (file_exists($file)) { - if (!dol_delete_file($dir)) + if (!dol_delete_file($file)) { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + $this->error=$langs->trans("ErrorCanNotDeleteFile",$dir); return 0; } - } } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } $result = 1; } else diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 32abf308ed6..0da8d2d1917 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -1487,6 +1487,15 @@ function dol_delete_file($file) return unlink($file); } +/** + \brief Effacement d'un répertoire + \param file répertoire a effacer +*/ +function dol_delete_dir($dir) +{ + return rmdir($dir); +} + /** \brief Fonction print_barre_liste