Skip to content

Commit 68b7858

Browse files
committed
ACP2E-2093: Issue when uploading image with the same name while deleting the old image
- Fixed the database compare issue.
1 parent 412c2cb commit 68b7858

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,34 @@ public function __construct(
8888
*/
8989
public function removeDeletedImagesFromCache(array $files)
9090
{
91-
$imageArguments = $this->presentationConfig
92-
->getViewConfig(['area' => \Magento\Framework\App\Area::AREA_FRONTEND])
93-
->getMediaAttributes(
94-
'Magento_Catalog',
95-
Image::MEDIA_TYPE_CONFIG_NODE,
96-
'product_page_image_small'
97-
);
91+
if (count($files) > 0) {
92+
$imageArguments = $this->presentationConfig
93+
->getViewConfig(['area' => \Magento\Framework\App\Area::AREA_FRONTEND])
94+
->getMediaAttributes(
95+
'Magento_Catalog',
96+
Image::MEDIA_TYPE_CONFIG_NODE,
97+
'product_page_image_small'
98+
);
9899

99-
$imageMiscParams = $this->imageParamsBuilder->build($imageArguments);
100+
$imageMiscParams = $this->imageParamsBuilder->build($imageArguments);
100101

101-
if (isset($imageMiscParams['image_type'])) {
102-
unset($imageMiscParams['image_type']);
103-
}
102+
if (isset($imageMiscParams['image_type'])) {
103+
unset($imageMiscParams['image_type']);
104+
}
104105

105-
$cacheId = $this->encryptor->hash(
106-
implode('_', $this->convertImageMiscParamsToReadableFormat
107-
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
108-
Encryptor::HASH_VERSION_MD5
109-
);
106+
$cacheId = $this->encryptor->hash(
107+
implode('_', $this->convertImageMiscParamsToReadableFormat
108+
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
109+
Encryptor::HASH_VERSION_MD5
110+
);
110111

111-
$catalogPath = $this->mediaConfig->getBaseMediaPath();
112+
$catalogPath = $this->mediaConfig->getBaseMediaPath();
112113

113-
foreach ($files as $filePath) {
114-
$this->mediaDirectory->delete(
115-
$catalogPath . '/cache/' . $cacheId . '/' . $filePath
116-
);
114+
foreach ($files as $filePath) {
115+
$this->mediaDirectory->delete(
116+
$catalogPath . '/cache/' . $cacheId . '/' . $filePath
117+
);
118+
}
117119
}
118120
return null;
119121
}

0 commit comments

Comments
 (0)