Skip to content

Commit

Permalink
MAGETWO-70395: Fixed pointless exception in logs every time a categor…
Browse files Browse the repository at this point in the history
…y with image is saved #9904

 - fixed unit tests and code style
  • Loading branch information
Oleksii Korshenko committed Jul 5, 2017
1 parent b96019f commit 0ac82eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ private function getImageUploader()
return $this->imageUploader;
}

/**
* Check if temporary file is available for new image upload.
*
* @param array $value
* @return bool
*/
private function isTmpFileAvailable($value)
{
return is_array($value) && isset($value[0]['tmp_name']);
}

/**
* Save uploaded file and set its name to category
*
Expand All @@ -128,17 +139,13 @@ public function afterSave($object)
{
$value = $object->getData($this->additionalData . $this->getAttribute()->getName());

if(isset($value[0]['tmp_name'])) {
// A file was just uploaded, so process it
if ($imageName = $this->getUploadedImageName($value)) {
try {
$this->getImageUploader()->moveFileFromTmp($imageName);
} catch (\Exception $e) {
$this->_logger->critical($e);
}
if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
try {
$this->getImageUploader()->moveFileFromTmp($imageName);
} catch (\Exception $e) {
$this->_logger->critical($e);
}
}

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function testAfterSaveWithAdditionalData($value)
$object = new \Magento\Framework\DataObject(
[
'test_attribute' => $value,
'_additional_data_test_attribute' => [['name' => 'test1234.jpg']]
'_additional_data_test_attribute' => [['name' => 'test1234.jpg', 'tmp_name' => 'test-test-1234']]
]
);

Expand Down Expand Up @@ -284,7 +284,7 @@ public function testAfterSaveWithExceptions()

$object = new \Magento\Framework\DataObject(
[
'_additional_data_test_attribute' => [['name' => 'test1234.jpg']]
'_additional_data_test_attribute' => [['name' => 'test1234.jpg', 'tmp_name' => 'test-test-1234']]
]
);

Expand Down

0 comments on commit 0ac82eb

Please sign in to comment.