Fix: [ bug #1062 ] Documents lost in propals and contracts validating

This commit is contained in:
simnandez 2013-09-12 16:55:49 +02:00
parent 16e2de1d7b
commit 002e248f00
3 changed files with 62 additions and 5 deletions

View File

@ -125,6 +125,7 @@ Fix: Compatiblity with multicompany module
Fix: Edit propal line was losing product supplier price id Fix: Edit propal line was losing product supplier price id
Fix: Delete linked element to supplier invoice when deleted Fix: Delete linked element to supplier invoice when deleted
Fix: [ bug #1061 ] Bad info shipped products Fix: [ bug #1061 ] Bad info shipped products
Fix: [ bug #1062 ] Documents lost in propals and contracts validating
Qual: Add travis-ci integration Qual: Add travis-ci integration

View File

@ -1271,6 +1271,8 @@ class Propal extends CommonObject
*/ */
function valid($user, $notrigger=0) function valid($user, $notrigger=0)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
global $conf,$langs; global $conf,$langs;
$error=0; $error=0;
@ -1317,8 +1319,32 @@ class Propal extends CommonObject
// Fin appel triggers // 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->brouillon=0;
$this->statut = 1; $this->statut = 1;
$this->user_valid_id=$user->id; $this->user_valid_id=$user->id;
@ -1327,7 +1353,7 @@ class Propal extends CommonObject
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }

View File

@ -281,6 +281,7 @@ class Contrat extends CommonObject
*/ */
function validate($user) function validate($user)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
global $langs, $conf; global $langs, $conf;
$error=0; $error=0;
@ -315,7 +316,36 @@ class Contrat extends CommonObject
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
return 1; 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;
}
else
{
return -1;
}
} }
else else
{ {