From b69d2800ef035d46e8fef6fe0067ffc0e72a6fe9 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 2 Mar 2018 18:59:30 +0100 Subject: [PATCH] Fix: check if file name already exists --- htdocs/core/actions_linkedfiles.inc.php | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 2ef3191154d..4e9e0063dc3 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -202,18 +202,26 @@ elseif ($action == 'renamefile' && GETPOST('renamefilesave','alpha')) $srcpath = $upload_dir.'/'.$filenamefrom; $destpath = $upload_dir.'/'.$filenameto; - $result = dol_move($srcpath, $destpath); - if ($result) + if (!file_exists($destpath)) { - if ($object->id) + $result = dol_move($srcpath, $destpath); + if ($result) { - $object->addThumbs($destpath); + if ($object->id) + { + $object->addThumbs($destpath); + } + + // TODO Add revert function of addThumbs to remove for old name + //$object->delThumbs($srcpath); + + setEventMessages($langs->trans("FileRenamed"), null); + } + else + { + $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now. + setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors'); } - - // TODO Add revert function of addThumbs to remove for old name - //$object->delThumbs($srcpath); - - setEventMessages($langs->trans("FileRenamed"), null); } else {