From 595697d68c328d749ea5144e8cab226680a2db9d Mon Sep 17 00:00:00 2001 From: Mohamed ELIDRISSI <67818913+elidrissidev@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:32:44 +0100 Subject: [PATCH 1/2] Fix exception logged when no Category image is uploaded --- lib/Varien/File/Uploader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Varien/File/Uploader.php b/lib/Varien/File/Uploader.php index 46cad1906a1..34b7d4e2929 100644 --- a/lib/Varien/File/Uploader.php +++ b/lib/Varien/File/Uploader.php @@ -161,10 +161,10 @@ public function __construct($fileId) $this->_setUploadFileId($fileId); if (empty($this->_file['tmp_name']) || !file_exists($this->_file['tmp_name'])) { $errorCode = $this->_file['error'] ?? 0; + $code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0; if ($errorCode && isset(self::UPLOAD_ERRORS[$errorCode])) { - throw new Exception(self::UPLOAD_ERRORS[$errorCode]); + throw new Exception(self::UPLOAD_ERRORS[$errorCode], $code); } - $code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0; throw new Exception('File was not uploaded.', $code); } else { $this->_fileExists = true; From de482b259be14894b00f41481e5648d7d98b032f Mon Sep 17 00:00:00 2001 From: Mohamed ELIDRISSI <67818913+elidrissidev@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:55:39 +0100 Subject: [PATCH 2/2] Deprecate TMP_NAME_EMPTY in favor of UPLOAD_ERR_NO_FILE --- .../Model/Category/Attribute/Backend/Image.php | 2 +- lib/Varien/File/Uploader.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php index c5e793c2b16..db6e845e6fe 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php +++ b/app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php @@ -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); } } diff --git a/lib/Varien/File/Uploader.php b/lib/Varien/File/Uploader.php index 34b7d4e2929..05ecfc8b863 100644 --- a/lib/Varien/File/Uploader.php +++ b/lib/Varien/File/Uploader.php @@ -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 @@ -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; - $code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0; - if ($errorCode && isset(self::UPLOAD_ERRORS[$errorCode])) { - throw new Exception(self::UPLOAD_ERRORS[$errorCode], $code); + if (isset(self::UPLOAD_ERRORS[$errorCode])) { + throw new Exception(self::UPLOAD_ERRORS[$errorCode], $errorCode); } - throw new Exception('File was not uploaded.', $code); } else { $this->_fileExists = true; } @@ -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)) {