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

Fix exception logged when no Category image is uploaded #3086

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
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 @@ -60,7 +60,7 @@ public function afterSave($object)
$object->setData($this->getAttribute()->getName(), $result['file']);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (Exception $e) {
if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
Mage::logException($e);
}
}
Expand Down
14 changes: 8 additions & 6 deletions lib/Varien/File/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ class Varien_File_Uploader

public const SINGLE_STYLE = 0;
public const MULTIPLE_STYLE = 1;
public const TMP_NAME_EMPTY = 666;

/**
* @deprecated Use UPLOAD_ERR_NO_FILE instead
*/
public const TMP_NAME_EMPTY = UPLOAD_ERR_NO_FILE;

/**
* Resulting of uploaded file
Expand All @@ -161,11 +165,9 @@ public function __construct($fileId)
$this->_setUploadFileId($fileId);
if (empty($this->_file['tmp_name']) || !file_exists($this->_file['tmp_name'])) {
$errorCode = $this->_file['error'] ?? 0;
if ($errorCode && isset(self::UPLOAD_ERRORS[$errorCode])) {
throw new Exception(self::UPLOAD_ERRORS[$errorCode]);
if (isset(self::UPLOAD_ERRORS[$errorCode])) {
throw new Exception(self::UPLOAD_ERRORS[$errorCode], $errorCode);
}
$code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0;
throw new Exception('File was not uploaded.', $code);
} else {
$this->_fileExists = true;
}
Expand Down Expand Up @@ -509,7 +511,7 @@ private function _getMimeType()
private function _setUploadFileId($fileId)
{
if (empty($_FILES)) {
throw new Exception('$_FILES array is empty', self::TMP_NAME_EMPTY);
throw new Exception('$_FILES array is empty', UPLOAD_ERR_NO_FILE);
}

if (is_array($fileId)) {
Expand Down