From e3c7bb41b890c8a124c9d385731a955630ea3f13 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Mon, 18 Nov 2024 12:47:31 +0100 Subject: [PATCH] Add a parameter to optionally copy the file, but it will still be moved by default --- .../install/files/lib/data/file/FileEditor.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/data/file/FileEditor.class.php b/wcfsetup/install/files/lib/data/file/FileEditor.class.php index 50564a6e8d..d3e5ac3d57 100644 --- a/wcfsetup/install/files/lib/data/file/FileEditor.class.php +++ b/wcfsetup/install/files/lib/data/file/FileEditor.class.php @@ -117,7 +117,8 @@ class FileEditor extends DatabaseObjectEditor public static function createFromExistingFile( string $pathname, string $originalFilename, - string $objectTypeName + string $objectTypeName, + bool $copy = false ): ?File { if (!\is_readable($pathname)) { return null; @@ -174,10 +175,11 @@ class FileEditor extends DatabaseObjectEditor \mkdir($filePath, recursive: true); } - \rename( - $pathname, - $filePath . $file->getSourceFilename() - ); + if ($copy) { + \copy($pathname, $filePath . $file->getSourceFilename()); + } else { + \rename($pathname, $filePath . $file->getSourceFilename()); + } return $file; } -- 2.20.1