Skip to content

Commit 057c268

Browse files
MC-39766: [AWS S3] Bug fixes (#6437)
* MC-39766: [AWS S3] Video cannot be added to the product * MC-39799: Issue with downloading exported product with S3 storage
1 parent 5cc7163 commit 057c268

File tree

4 files changed

+30
-66
lines changed

4 files changed

+30
-66
lines changed

app/code/Magento/AwsS3/Model/HttpLoggerHandler.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function execute()
6161
$resultRedirect = $this->resultRedirectFactory->create();
6262
$resultRedirect->setPath('adminhtml/export/index');
6363
$fileName = $this->getRequest()->getParam('filename');
64-
$exportDirectory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_EXPORT);
64+
$exportDirectory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
6565

6666
try {
67-
$fileExist = $exportDirectory->isExist($fileName);
67+
$fileExist = $exportDirectory->isExist('export/' . $fileName);
6868
} catch (Throwable $e) {
6969
$fileExist = false;
7070
}

app/code/Magento/ProductVideo/Controller/Adminhtml/Product/Gallery/RetrieveImage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ protected function appendResultSaveRemoteImage($fileName)
180180
$result['name'] = $fileInfo['basename'];
181181
$result['type'] = $this->imageAdapter->getMimeType();
182182
$result['error'] = 0;
183-
$result['size'] = filesize($this->appendAbsoluteFileSystemPath($fileName));
183+
$result['size'] = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA)
184+
->getDriver()->stat(($this->appendAbsoluteFileSystemPath($fileName)))['size'];
184185
$result['url'] = $this->mediaConfig->getTmpMediaUrl($tmpFileName);
185186
$result['file'] = $tmpFileName;
186187
return $result;

app/code/Magento/ProductVideo/Test/Unit/Controller/Adminhtml/Product/Gallery/RetrieveImageTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Catalog\Model\Product\Media\Config;
1212
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Controller\Result\Raw;
1314
use Magento\Framework\Controller\Result\RawFactory;
1415
use Magento\Framework\DataObject;
1516
use Magento\Framework\Filesystem;
@@ -99,6 +100,11 @@ class RetrieveImageTest extends TestCase
99100
*/
100101
private $fileDriverMock;
101102

103+
/**
104+
* @var Raw|MockObject
105+
*/
106+
private $responseMock;
107+
102108
private function setupObjectManagerForCheckImageExist($return)
103109
{
104110
$objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
@@ -119,8 +125,8 @@ protected function setUp(): void
119125
->createMock(NotProtectedExtension::class);
120126
$this->rawFactoryMock =
121127
$this->createPartialMock(RawFactory::class, ['create']);
122-
$response = new DataObject();
123-
$this->rawFactoryMock->expects($this->once())->method('create')->willReturn($response);
128+
$this->responseMock = $this->createMock(Raw::class);
129+
$this->rawFactoryMock->expects($this->once())->method('create')->willReturn($this->responseMock);
124130
$this->configMock = $this->createMock(Config::class);
125131
$this->filesystemMock = $this->createMock(Filesystem::class);
126132
$this->adapterMock =
@@ -140,6 +146,8 @@ protected function setUp(): void
140146
->getMockForAbstractClass();
141147
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->request);
142148
$this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($managerMock);
149+
$this->fileDriverMock->method('stat')
150+
->willReturn(['size' => 200]);
143151

144152
$this->image = $objectManager->getObject(
145153
RetrieveImage::class,
@@ -172,12 +180,24 @@ public function testExecute()
172180
$writeInterface = $this->createMock(
173181
WriteInterface::class
174182
);
183+
$writeInterface->method('getDriver')
184+
->willReturn($this->fileDriverMock);
175185
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
176186
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
177187
$this->abstractAdapter->expects($this->any())->method('validateUploadFile')->willReturn('true');
178188
$this->validatorMock->expects($this->once())->method('isValid')->with('jpg')->willReturn('true');
179189
$this->filesystemMock->expects($this->once())->method('getDirectoryWrite')->willReturn($writeInterface);
180190
$this->curlMock->expects($this->once())->method('read')->willReturn('testimage');
191+
$this->responseMock->expects(self::once())
192+
->method('setContents')
193+
->with(json_encode([
194+
'name' => 'test.jpg',
195+
'type' => null,
196+
'error' => 0,
197+
'size' => 200,
198+
'url' => null,
199+
'file' => '/t/e/test.jpg'
200+
], JSON_THROW_ON_ERROR));
181201

182202
$this->image->execute();
183203
}
@@ -192,6 +212,8 @@ public function testExecuteInvalidFileImage()
192212
);
193213
$readInterface = $this->createMock(ReadInterface::class);
194214
$writeInterface = $this->createMock(WriteInterface::class);
215+
$writeInterface->method('getDriver')
216+
->willReturn($this->fileDriverMock);
195217
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
196218
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
197219
$this->abstractAdapter->expects($this->any())
@@ -216,6 +238,8 @@ public function testExecuteInvalidFileType()
216238
);
217239
$readInterface = $this->createMock(ReadInterface::class);
218240
$writeInterface = $this->createMock(WriteInterface::class);
241+
$writeInterface->method('getDriver')
242+
->willReturn($this->fileDriverMock);
219243
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($readInterface);
220244
$readInterface->expects($this->any())->method('getAbsolutePath')->willReturn('');
221245
$this->abstractAdapter->expects($this->never())->method('validateUploadFile');

0 commit comments

Comments
 (0)