Add a parameter to optionally copy the file, but it will still be moved by default
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 18 Nov 2024 11:47:31 +0000 (12:47 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 18 Nov 2024 11:47:31 +0000 (12:47 +0100)
wcfsetup/install/files/lib/data/file/FileEditor.class.php

index 50564a6e8d82923d4f46da81d8e4be936fe42446..d3e5ac3d5783e0d3bbe7e0ebd0855cf239ce1d85 100644 (file)
@@ -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;
     }