Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit cc76623

Browse files
committed
Merge remote-tracking branch 'tango/MC-29519' into MC-29519
2 parents 48e8d59 + 9297939 commit cc76623

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\Category\Attribute\Backend;
77

8+
use Magento\Catalog\Model\ImageUploader;
89
use Magento\Framework\App\Filesystem\DirectoryList;
910
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\File\Uploader;
@@ -48,7 +49,7 @@ class Image extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
4849
protected $_logger;
4950

5051
/**
51-
* @var \Magento\Catalog\Model\ImageUploader
52+
* @var ImageUploader
5253
*/
5354
private $imageUploader;
5455

@@ -67,18 +68,22 @@ class Image extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
6768
* @param \Magento\Framework\Filesystem $filesystem
6869
* @param \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
6970
* @param StoreManagerInterface $storeManager
71+
* @param ImageUploader $imageUploader
7072
*/
7173
public function __construct(
7274
\Psr\Log\LoggerInterface $logger,
7375
\Magento\Framework\Filesystem $filesystem,
7476
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
75-
StoreManagerInterface $storeManager = null
77+
StoreManagerInterface $storeManager = null,
78+
ImageUploader $imageUploader = null
7679
) {
7780
$this->_filesystem = $filesystem;
7881
$this->_fileUploaderFactory = $fileUploaderFactory;
7982
$this->_logger = $logger;
80-
$this->storeManager = $storeManager ?
81-
$storeManager : ObjectManager::getInstance()->get(StoreManagerInterface::class);
83+
$this->storeManager = $storeManager ??
84+
ObjectManager::getInstance()->get(StoreManagerInterface::class);
85+
$this->imageUploader = $imageUploader ??
86+
ObjectManager::getInstance()->get(ImageUploader::class);
8287
}
8388

8489
/**
@@ -107,10 +112,9 @@ private function getUploadedImageName($value)
107112
*/
108113
private function checkUniqueImageName(string $imageName): string
109114
{
110-
$imageUploader = $this->getImageUploader();
111115
$mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
112116
$imageAbsolutePath = $mediaDirectory->getAbsolutePath(
113-
$imageUploader->getBasePath() . DIRECTORY_SEPARATOR . $imageName
117+
$this->imageUploader->getBasePath() . DIRECTORY_SEPARATOR . $imageName
114118
);
115119

116120
$imageName = Uploader::getNewFilename($imageAbsolutePath);
@@ -138,7 +142,7 @@ public function beforeSave($object)
138142
/** @var StoreInterface $store */
139143
$store = $this->storeManager->getStore();
140144
$baseMediaDir = $store->getBaseMediaDir();
141-
$newImgRelativePath = $this->getImageUploader()->moveFileFromTmp($imageName, true);
145+
$newImgRelativePath = $this->imageUploader->moveFileFromTmp($imageName, true);
142146
$value[0]['url'] = '/' . $baseMediaDir . '/' . $newImgRelativePath;
143147
$value[0]['name'] = $value[0]['url'];
144148
} catch (\Exception $e) {
@@ -164,23 +168,6 @@ public function beforeSave($object)
164168
return parent::beforeSave($object);
165169
}
166170

167-
/**
168-
* Get Instance of Category Image Uploader.
169-
*
170-
* @return \Magento\Catalog\Model\ImageUploader
171-
*
172-
* @deprecated 101.0.0
173-
*/
174-
private function getImageUploader()
175-
{
176-
if ($this->imageUploader === null) {
177-
$this->imageUploader = \Magento\Framework\App\ObjectManager::getInstance()
178-
->get(\Magento\Catalog\CategoryImageUpload::class);
179-
}
180-
181-
return $this->imageUploader;
182-
}
183-
184171
/**
185172
* Check if temporary file is available for new image upload.
186173
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private function setUpModelForTests()
320320
->will(
321321
$this->returnCallback(
322322
function ($class, $params = []) use ($imageUploaderMock) {
323-
if ($class == \Magento\Catalog\CategoryImageUpload::class) {
323+
if ($class == "\Magento\Catalog\CategoryImageUpload") {
324324
return $imageUploaderMock;
325325
}
326326

app/code/Magento/Catalog/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@
238238
<argument name="imageUploader" xsi:type="object">Magento\Catalog\CategoryImageUpload</argument>
239239
</arguments>
240240
</type>
241+
<type name="Magento\Catalog\Model\Category\Attribute\Backend\Image">
242+
<arguments>
243+
<argument name="imageUploader" xsi:type="object">Magento\Catalog\CategoryImageUpload</argument>
244+
</arguments>
245+
</type>
241246
<type name="Magento\Catalog\Model\Session">
242247
<arguments>
243248
<argument name="storage" xsi:type="object">Magento\Catalog\Model\Session\Storage</argument>

0 commit comments

Comments
 (0)