Skip to content

Commit

Permalink
Fixed exception logged when no Category image is uploaded (#3086)
Browse files Browse the repository at this point in the history
  • Loading branch information
elidrissidev committed Mar 15, 2023
1 parent 783fa68 commit 089c00c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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

0 comments on commit 089c00c

Please sign in to comment.