diff --git a/ChangeLog b/ChangeLog index a805ef6786a..58aaf22595e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -125,6 +125,7 @@ Fix: Compatiblity with multicompany module Fix: Edit propal line was losing product supplier price id Fix: Delete linked element to supplier invoice when deleted Fix: [ bug #1061 ] Bad info shipped products +Fix: [ bug #1062 ] Documents lost in propals and contracts validating Qual: Add travis-ci integration diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index c653a8e57a1..6a939068639 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1271,6 +1271,8 @@ class Propal extends CommonObject */ function valid($user, $notrigger=0) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + global $conf,$langs; $error=0; @@ -1316,9 +1318,33 @@ class Propal extends CommonObject } // Fin appel triggers } - - if (! $error) - { + + + if (! $error) + { + // Rename directory if dir was a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + // Rename of propal directory ($this->ref = old ref, $num = new ref) + // to not lose the linked files + $facref = dol_sanitizeFileName($this->ref); + $snumfa = dol_sanitizeFileName($num); + $dirsource = $conf->propal->dir_output.'/'.$facref; + $dirdest = $conf->propal->dir_output.'/'.$snumfa; + if (file_exists($dirsource)) + { + dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); + + if (@rename($dirsource, $dirdest)) + { + + dol_syslog("Rename ok"); + // Deleting old PDF in new rep + dol_delete_file($conf->propal->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); + } + } + } + $this->brouillon=0; $this->statut = 1; $this->user_valid_id=$user->id; @@ -1327,7 +1353,7 @@ class Propal extends CommonObject return 1; } else - { + { $this->db->rollback(); return -2; } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index bbb621a8887..12d474b72dd 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -281,6 +281,7 @@ class Contrat extends CommonObject */ function validate($user) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; global $langs, $conf; $error=0; @@ -314,8 +315,37 @@ class Contrat extends CommonObject $result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers + + if (! $error) + { + // Rename directory if dir was a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + // Rename of propal directory ($this->ref = old ref, $num = new ref) + // to not lose the linked files + $facref = dol_sanitizeFileName($this->ref); + $snumfa = dol_sanitizeFileName($num); + $dirsource = $conf->contract->dir_output.'/'.$facref; + $dirdest = $conf->contract->dir_output.'/'.$snumfa; + if (file_exists($dirsource)) + { + dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); + + if (@rename($dirsource, $dirdest)) + { + dol_syslog("Rename ok"); + // Deleting old PDF in new rep + dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); + } + } + } - return 1; + return 1; + } + else + { + return -1; + } } else {