Fix: Validation of order if a file was attached

This commit is contained in:
Laurent Destailleur 2009-01-15 00:17:57 +00:00
parent 4a794016fb
commit af1cede0ed
3 changed files with 37 additions and 44 deletions

View File

@ -29,6 +29,7 @@ For users:
- Fix: Clicktodial plugin works correctly now - Fix: Clicktodial plugin works correctly now
- Fix: Multiprices features works correctly. - Fix: Multiprices features works correctly.
- Fix: Project module and task creation. - Fix: Project module and task creation.
- Fix: Validation of order if a file was attached.
For translators: For translators:
- Added ca_ES language files - Added ca_ES language files

View File

@ -251,34 +251,26 @@ class Commande extends CommonObject
// On efface le repertoire de pdf provisoire // On efface le repertoire de pdf provisoire
if (eregi('^\(PROV', $this->ref)) if (eregi('^\(PROV', $this->ref))
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $numfa = nouvelle ref)
// afin de ne pas perdre les fichiers attachés
$comref = sanitizeFileName($this->ref); $comref = sanitizeFileName($this->ref);
if ($conf->commande->dir_output) $snum = sanitizeFileName($num);
$dirsource = $conf->commande->dir_output.'/'.$comref;
$dirdest = $conf->commande->dir_output.'/'.$snum;
if (file_exists($dirsource))
{ {
$dir = $conf->commande->dir_output . "/" . $comref ; dol_syslog("Commande::valid() rename dir ".$dirsource." into ".$dirdest);
$file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
if (file_exists($file))
{
commande_delete_preview($this->db, $this->id, $this->ref);
if (!dol_delete_file($file)) if (@rename($dirsource, $dirdest))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
$this->db->rollback();
return 0;
}
}
if (file_exists($dir))
{ {
if (!dol_delete_dir($dir)) dol_syslog("Rename ok");
{ // Suppression ancien fichier PDF dans nouveau rep
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'.*');
$this->db->rollback();
return 0;
}
} }
} }
} }
// If stock is incremented on validate order, we must increment it // If stock is incremented on validate order, we must increment it
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {

View File

@ -1310,11 +1310,11 @@ class Facture extends CommonObject
$dirdest = $conf->facture->dir_output.'/'.$snumfa; $dirdest = $conf->facture->dir_output.'/'.$snumfa;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog("Facture::set_valid() renommage rep ".$dirsource." en ".$dirdest); dol_syslog("Facture::set_valid() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
dol_syslog("Renommage ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*'); dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'.*');
} }