Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cropping as new image #65

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2433,17 +2433,20 @@ 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,
'message' => $this->alertMessageHtml($this->mediaManager->modx->lexicon('mediamanager.files.error.file_upload', array('file' => $file['name'])), 'danger')
];
}

$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;

Expand Down Expand Up @@ -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
Expand Down