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()
118
118
return $ this ->imageUploader ;
119
119
}
120
120
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
+
121
132
/**
122
133
* Save uploaded file and set its name to category
123
134
*
@@ -128,14 +139,13 @@ public function afterSave($object)
128
139
{
129
140
$ value = $ object ->getData ($ this ->additionalData . $ this ->getAttribute ()->getName ());
130
141
131
- if ($ imageName = $ this ->getUploadedImageName ($ value )) {
142
+ if ($ this -> isTmpFileAvailable ( $ value ) && $ imageName = $ this ->getUploadedImageName ($ value )) {
132
143
try {
133
144
$ this ->getImageUploader ()->moveFileFromTmp ($ imageName );
134
145
} catch (\Exception $ e ) {
135
146
$ this ->_logger ->critical ($ e );
136
147
}
137
148
}
138
-
139
149
return $ this ;
140
150
}
141
151
}
Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ public function testAfterSaveWithAdditionalData($value)
240
240
$ object = new \Magento \Framework \DataObject (
241
241
[
242
242
'test_attribute ' => $ value ,
243
- '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' ]]
243
+ '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' , ' tmp_name ' => ' test-test-1234 ' ]]
244
244
]
245
245
);
246
246
@@ -284,7 +284,7 @@ public function testAfterSaveWithExceptions()
284
284
285
285
$ object = new \Magento \Framework \DataObject (
286
286
[
287
- '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' ]]
287
+ '_additional_data_test_attribute ' => [['name ' => 'test1234.jpg ' , ' tmp_name ' => ' test-test-1234 ' ]]
288
288
]
289
289
);
290
290
You can’t perform that action at this time.
0 commit comments