Skip to content

Commit

Permalink
Merge pull request #8426 from atm-ph/fix_5.0_files_lost_on_contract
Browse files Browse the repository at this point in the history
Fix documents are lost if we rename contrat ref
  • Loading branch information
eldy committed Mar 21, 2018
2 parents faef7a2 + 2094c48 commit 7d5c3a5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion htdocs/contrat/card.php
Expand Up @@ -872,12 +872,27 @@
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}


$old_ref = $object->ref;
$result = $object->setValueFrom('ref', GETPOST('ref','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = 'editref';
} else {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$old_filedir = $conf->contrat->dir_output . '/' . dol_sanitizeFileName($old_ref);
$new_filedir = $conf->contrat->dir_output . '/' . dol_sanitizeFileName($object->ref);

$files = dol_dir_list($old_filedir);
if (!empty($files))
{
if (!is_dir($new_filedir)) dol_mkdir($new_filedir);
foreach ($files as $file)
{
dol_move($file['fullname'], $new_filedir.'/'.$file['name']);
}
}

header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
exit;
}
Expand Down

0 comments on commit 7d5c3a5

Please sign in to comment.