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: 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

View File

@ -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;
}

View File

@ -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
{