From cad7bdc74be379faff4f72beb1e00e6cc9c93654 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Wed, 21 Mar 2018 11:54:25 +0100 Subject: [PATCH 1/2] Fix documents are lost if we rename contrat ref --- htdocs/contrat/card.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 2409056cb1f4c..6e9d5d1bff00b 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -872,12 +872,26 @@ 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)) + { + foreach ($files as $file) + { + dol_move($file['fullname'], $new_filedir.'/'.$file['name']); + } + } + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); exit; } From 2094c48b7fbe6edb6969e7e55ebfe6a172461aa6 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Wed, 21 Mar 2018 12:14:04 +0100 Subject: [PATCH 2/2] Fix missing folder with multientity --- htdocs/contrat/card.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 6e9d5d1bff00b..ccd21eecccd5b 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -886,6 +886,7 @@ $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']);