Skip to content

Commit f0cb267

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70395: Fixed pointless exception in logs every time a category with image is saved #9904
2 parents ff58f45 + 0ac82eb commit f0cb267

File tree

2 files changed

+14
-4
lines changed
  • app/code/Magento/Catalog

2 files changed

+14
-4
lines changed

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

app/code/Magento/Catalog/Test/Unit/Model/Category/Attribute/Backend/ImageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)