From 319a715477d1271a778f44ba3d5f19e249524566 Mon Sep 17 00:00:00 2001 From: Romain Tripault Date: Mon, 23 Jan 2023 13:49:17 +0100 Subject: [PATCH] Fixed cropping as new image --- .../model/mediamanager/classes/files.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/components/mediamanager/model/mediamanager/classes/files.class.php b/core/components/mediamanager/model/mediamanager/classes/files.class.php index 9aba1f0..a1b4460 100644 --- a/core/components/mediamanager/model/mediamanager/classes/files.class.php +++ b/core/components/mediamanager/model/mediamanager/classes/files.class.php @@ -2433,8 +2433,11 @@ public function duplicateFile($file, $imageData) $fileName = explode('.', $file['name']); // @TODO: Need better solution (what if a filename contains multiple dots?) $fileName = $this->createUniqueFile($this->uploadDirectory . $this->uploadDirectoryMonth, $fileName[0], $file['file_type']); + $destinationPath = $this->uploadDirectoryMonth . $fileName; + $destinationAbsolute = $this->uploadDirectory . $destinationPath; + // Create new file - $fileCreated = file_put_contents($this->uploadDirectory . $this->uploadDirectoryMonth . $fileName, $imageData); + $fileCreated = file_put_contents($destinationAbsolute, $imageData); if ($fileCreated === false) { return [ 'status' => self::STATUS_ERROR, @@ -2442,8 +2445,8 @@ public function duplicateFile($file, $imageData) ]; } - $file['size'] = filesize($this->uploadDirectory . $this->uploadDirectoryMonth . $fileName); - $file['hash'] = $this->getFileHashByPath($this->uploadDirectory . $this->uploadDirectoryMonth . $fileName); + $file['size'] = filesize($destinationAbsolute); + $file['hash'] = $this->getFileHashByPath($destinationAbsolute); $file['extension'] = $file['file_type']; $file['unique_name'] = $fileName; @@ -2473,6 +2476,8 @@ public function duplicateFile($file, $imageData) // Add file to database $fileId = $this->insertFile($file, $data); + // we update the path here so that "version" file uses the newly created image and not the source duplicated + $file['path'] = $destinationPath; $versionCreated = $this->saveFileVersion($fileId, $file, 'create'); if (!$fileId || !$versionCreated) { // Remove file from server if saving failed