Skip to content

Commit eb5dc54

Browse files
committed
ACP2E-2093: Issue when uploading image with the same name while deleting the old image
- Addressed the CR comments.
1 parent 449068c commit eb5dc54

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

app/code/Magento/Catalog/Model/Product/Image/RemoveDeletedImagesFromCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function removeDeletedImagesFromCache(array $files): void
9494
Image::MEDIA_TYPE_CONFIG_NODE
9595
);
9696

97+
$catalogPath = $this->mediaConfig->getBaseMediaPath();
98+
9799
foreach ($images as $imageData) {
98100
$imageMiscParams = $this->imageParamsBuilder->build($imageData);
99101

@@ -107,8 +109,6 @@ public function removeDeletedImagesFromCache(array $files): void
107109
Encryptor::HASH_VERSION_MD5
108110
);
109111

110-
$catalogPath = $this->mediaConfig->getBaseMediaPath();
111-
112112
foreach ($files as $filePath) {
113113
$this->mediaDirectory->delete(
114114
$catalogPath . '/cache/' . $cacheId . '/' . $filePath

app/code/Magento/Catalog/Test/Unit/Model/Product/Image/RemoveDeletedImagesFromCacheTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,11 @@ class RemoveDeletedImagesFromCacheTest extends TestCase
6666

6767
protected function setUp(): void
6868
{
69-
$this->presentationConfig = $this->getMockBuilder(ConfigInterface::class)
70-
->disableOriginalConstructor()
71-
->getMock();
69+
$this->presentationConfig = $this->createMock(ConfigInterface::class);
7270

73-
$this->encryptor = $this->getMockBuilder(EncryptorInterface::class)
74-
->disableOriginalConstructor()
75-
->getMock();
71+
$this->encryptor = $this->createMock(EncryptorInterface::class);
7672

77-
$this->mediaConfig = $this->getMockBuilder(Config::class)
78-
->disableOriginalConstructor()
79-
->getMock();
73+
$this->mediaConfig = $this->createMock(Config::class);
8074

8175
$this->mediaDirectory = $this->createMock(Write::class);
8276

@@ -85,14 +79,10 @@ protected function setUp(): void
8579
->method('getDirectoryWrite')
8680
->willReturn($this->mediaDirectory);
8781

88-
$this->imageParamsBuilder = $this->getMockBuilder(ParamsBuilder::class)
89-
->disableOriginalConstructor()
90-
->getMock();
82+
$this->imageParamsBuilder = $this->createMock(ParamsBuilder::class);
9183

9284
$this->convertImageMiscParamsToReadableFormat = $this
93-
->getMockBuilder(ConvertImageMiscParamsToReadableFormat::class)
94-
->disableOriginalConstructor()
95-
->getMock();
85+
->createMock(ConvertImageMiscParamsToReadableFormat::class);
9686

9787
$this->model = new RemoveDeletedImagesFromCache(
9888
$this->presentationConfig,
@@ -103,9 +93,7 @@ protected function setUp(): void
10393
$this->convertImageMiscParamsToReadableFormat
10494
);
10595

106-
$this->viewMock = $this->getMockBuilder(View::class)
107-
->disableOriginalConstructor()
108-
->getMock();
96+
$this->viewMock = $this->createMock(View::class);
10997
}
11098

11199
/**

0 commit comments

Comments
 (0)