File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Model/Category/Attribute/Backend
Test/Unit/Model/Category/Attribute/Backend Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,17 @@ private function getImageUploader()
118118 return $ this ->imageUploader ;
119119 }
120120
121+ /**
122+ * Check if temporary file is available for new image upload.
123+ *
124+ * @param array $value
125+ * @return bool
126+ */
127+ private function isTmpFileAvailable ($ value )
128+ {
129+ return is_array ($ value ) && isset ($ value [0 ]['tmp_name ' ]);
130+ }
131+
121132 /**
122133 * Save uploaded file and set its name to category
123134 *
@@ -128,14 +139,13 @@ public function afterSave($object)
128139 {
129140 $ value = $ object ->getData ($ this ->additionalData . $ this ->getAttribute ()->getName ());
130141
131- if ($ imageName = $ this ->getUploadedImageName ($ value )) {
142+ if ($ this -> isTmpFileAvailable ( $ value ) && $ imageName = $ this ->getUploadedImageName ($ value )) {
132143 try {
133144 $ this ->getImageUploader ()->moveFileFromTmp ($ imageName );
134145 } catch (\Exception $ e ) {
135146 $ this ->_logger ->critical ($ e );
136147 }
137148 }
138-
139149 return $ this ;
140150 }
141151}
Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ public function testAfterSaveWithAdditionalData($value)
240240 $ object = new \Magento \Framework \DataObject (
241241 [
242242 'test_attribute ' => $ value ,
243- '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' ]]
243+ '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' , ' tmp_name ' => ' test-test-1234 ' ]]
244244 ]
245245 );
246246
@@ -284,7 +284,7 @@ public function testAfterSaveWithExceptions()
284284
285285 $ object = new \Magento \Framework \DataObject (
286286 [
287- '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' ]]
287+ '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' , ' tmp_name ' => ' test-test-1234 ' ]]
288288 ]
289289 );
290290
You can’t perform that action at this time.
0 commit comments