Skip to content

Commit 64c117b

Browse files
author
lakshmana
committed
ACP2E-1526 : changed logic based on build failures
1 parent ef6c9b8 commit 64c117b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media/ImageEntryConverter.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ImageEntryConverter implements EntryConverterInterface
2626
/**
2727
* Media Entry type code
2828
*/
29-
const MEDIA_TYPE_CODE = 'image';
29+
public const MEDIA_TYPE_CODE = 'image';
3030

3131
/**
3232
* @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory
@@ -68,7 +68,6 @@ public function __construct(
6868
ImageContentInterfaceFactory $imageContentInterface = null,
6969
Filesystem $filesystem = null,
7070
Mime $imageMime = null
71-
7271
) {
7372
$this->mediaGalleryEntryFactory = $mediaGalleryEntryFactory;
7473
$this->dataObjectHelper = $dataObjectHelper;
@@ -89,6 +88,7 @@ public function getMediaEntryType()
8988
* @param Product $product
9089
* @param array $rowData
9190
* @return ProductAttributeMediaGalleryEntryInterface $entry
91+
* @throws FileSystemException
9292
*/
9393
public function convertTo(Product $product, array $rowData)
9494
{
@@ -106,25 +106,17 @@ public function convertTo(Product $product, array $rowData)
106106
if (isset($image['value_id'])) {
107107
$entry->setId($image['value_id']);
108108
}
109-
$imageFileContent = file_get_contents($product->getMediaConfig()->getMediaUrl(($entry->getFile())));
109+
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
110+
$path = $mediaDirectory->getAbsolutePath($product->getMediaConfig()->getMediaPath($entry->getFile()));
111+
$imageFileContent = $mediaDirectory->getDriver()->fileGetContents($path);
110112
$entryContent = $this->imageContentInterface->create()
111113
->setName(basename($entry->getFile()))
112114
->setBase64EncodedData(base64_encode($imageFileContent))
113-
->setType($this->getImageMimeType($product,$entry));
115+
->setType($this->imageMime->getMimeType($path));
114116
$entry->setContent($entryContent);
115117
return $entry;
116118
}
117119

118-
/**
119-
* @throws FileSystemException
120-
*/
121-
public function getImageMimeType($product, $entry)
122-
{
123-
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
124-
$path = $directory->getAbsolutePath($product->getMediaConfig()->getMediaPath($entry->getFile()));
125-
return $this->imageMime->getMimeType($path);
126-
}
127-
128120
/**
129121
* @param ProductAttributeMediaGalleryEntryInterface $entry
130122
* @return array

0 commit comments

Comments
 (0)