Skip to content

Commit 6a0485f

Browse files
committed
Revert "making changes for Upload category image with same image name issue #17661"
This reverts commit 9a15e1f.
1 parent 9a15e1f commit 6a0485f

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,10 @@ private function fileResidesOutsideCategoryDir($value)
167167
public function afterSave($object)
168168
{
169169
$value = $object->getData($this->additionalData . $this->getAttribute()->getName());
170-
170+
171171
if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
172172
try {
173-
$imageName = $this->getImageUploader()->moveFileFromTmp($imageName);
174-
$attributeName = $this->getAttribute()->getName();
175-
$object->setData($attributeName, $imageName);
176-
$this->getAttribute()->getEntity()->saveAttribute($object, $attributeName);
173+
$this->getImageUploader()->moveFileFromTmp($imageName);
177174
} catch (\Exception $e) {
178175
$this->_logger->critical($e);
179176
}

app/code/Magento/Catalog/Model/ImageUploader.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,10 @@ public function moveFileFromTmp($imageName)
200200
{
201201
$baseTmpPath = $this->getBaseTmpPath();
202202
$basePath = $this->getBasePath();
203-
203+
204204
$baseImagePath = $this->getFilePath($basePath, $imageName);
205205
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);
206-
207-
$destinationFileAbsolutePath = $this->mediaDirectory->getAbsolutePath($baseImagePath);
208-
$fileInfo = pathinfo($destinationFileAbsolutePath);
209-
if (file_exists($destinationFileAbsolutePath)) {
210-
$index = 1;
211-
$imageName = $fileInfo['filename'] . '.' . $fileInfo['extension'];
212-
while (file_exists($fileInfo['dirname'] . '/' . $imageName)) {
213-
$imageName = $fileInfo['filename'] . '_' . $index . '.' . $fileInfo['extension'];
214-
$index++;
215-
}
216-
$baseImagePath = $this->getFilePath($basePath, $imageName);
217-
}
206+
218207
try {
219208
$this->coreFileStorageDatabase->copyFile(
220209
$baseTmpImagePath,
@@ -233,7 +222,7 @@ public function moveFileFromTmp($imageName)
233222
return $imageName;
234223
}
235224

236-
/**
225+
/**
237226
* Checking file for save and save it to tmp dir
238227
*
239228
* @param string $fileId
@@ -244,16 +233,16 @@ public function moveFileFromTmp($imageName)
244233
*/
245234
public function saveFileToTmpDir($fileId)
246235
{
247-
$baseTmpPath = $this->getBaseTmpPath();
236+
$baseTmpPath = $this->getBaseTmpPath();
248237

249238
/** @var \Magento\MediaStorage\Model\File\Uploader $uploader */
250239
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
251240
$uploader->setAllowedExtensions($this->getAllowedExtensions());
252241
$uploader->setAllowRenameFiles(true);
253242
if (!$uploader->checkMimeType($this->allowedMimeTypes)) {
254243
throw new \Magento\Framework\Exception\LocalizedException(__('File validation failed.'));
255-
}
256-
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
244+
}
245+
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
257246
unset($result['path']);
258247

259248
if (!$result) {

0 commit comments

Comments
 (0)