Skip to content

Commit 58c174d

Browse files
Merge branch 'application-server-part3' of github.com:magento-performance/magento2ce into ACPT-1360
2 parents 4765dc5 + d7512e3 commit 58c174d

File tree

32 files changed

+320
-110
lines changed

32 files changed

+320
-110
lines changed

app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77
namespace Magento\Backup\Controller\Adminhtml\Index;
88

9+
use Magento\Framework\App\Action\HttpGetActionInterface;
910
use Magento\Framework\App\Filesystem\DirectoryList;
1011

11-
class Download extends \Magento\Backup\Controller\Adminhtml\Index
12+
class Download extends \Magento\Backup\Controller\Adminhtml\Index implements HttpGetActionInterface
1213
{
1314
/**
1415
* @var \Magento\Framework\Controller\Result\RawFactory
@@ -66,17 +67,12 @@ public function execute()
6667

6768
$fileName = $this->_objectManager->get(\Magento\Backup\Helper\Data::class)->generateBackupDownloadName($backup);
6869

69-
$this->_fileFactory->create(
70+
return $this->_fileFactory->create(
7071
$fileName,
71-
null,
72+
['type' => 'filename', 'value' => $backup->getPath() . DIRECTORY_SEPARATOR . $backup->getFileName()],
7273
DirectoryList::VAR_DIR,
7374
'application/octet-stream',
7475
$backup->getSize()
7576
);
76-
77-
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
78-
$resultRaw = $this->resultRawFactory->create();
79-
$resultRaw->setContents($backup->output());
80-
return $resultRaw;
8177
}
8278
}

app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function setUp(): void
115115
->getMock();
116116
$this->backupModelMock = $this->getMockBuilder(Backup::class)
117117
->disableOriginalConstructor()
118-
->setMethods(['getTime', 'exists', 'getSize', 'output'])
118+
->setMethods(['getTime', 'exists', 'getSize', 'output', 'getPath', 'getFileName'])
119119
->getMock();
120120
$this->dataHelperMock = $this->getMockBuilder(Data::class)
121121
->disableOriginalConstructor()
@@ -169,8 +169,13 @@ public function testExecuteBackupFound()
169169
$type = 'db';
170170
$filename = 'filename';
171171
$size = 10;
172-
$output = 'test';
173-
172+
$path = 'testpath';
173+
$this->backupModelMock->expects($this->atLeastOnce())
174+
->method('getPath')
175+
->willReturn($path);
176+
$this->backupModelMock->expects($this->atLeastOnce())
177+
->method('getFileName')
178+
->willReturn($filename);
174179
$this->backupModelMock->expects($this->atLeastOnce())
175180
->method('getTime')
176181
->willReturn($time);
@@ -180,9 +185,6 @@ public function testExecuteBackupFound()
180185
$this->backupModelMock->expects($this->atLeastOnce())
181186
->method('getSize')
182187
->willReturn($size);
183-
$this->backupModelMock->expects($this->atLeastOnce())
184-
->method('output')
185-
->willReturn($output);
186188
$this->requestMock->expects($this->any())
187189
->method('getParam')
188190
->willReturnMap(
@@ -206,20 +208,14 @@ public function testExecuteBackupFound()
206208
$this->fileFactoryMock->expects($this->once())
207209
->method('create')->with(
208210
$filename,
209-
null,
211+
['type' => 'filename', 'value' => $path . '/' . $filename],
210212
DirectoryList::VAR_DIR,
211213
'application/octet-stream',
212214
$size
213215
)
214216
->willReturn($this->responseMock);
215-
$this->resultRawMock->expects($this->once())
216-
->method('setContents')
217-
->with($output);
218-
$this->resultRawFactoryMock->expects($this->once())
219-
->method('create')
220-
->willReturn($this->resultRawMock);
221217

222-
$this->assertSame($this->resultRawMock, $this->downloadController->execute());
218+
$this->assertSame($this->responseMock, $this->downloadController->execute());
223219
}
224220

225221
/**

app/code/Magento/Catalog/Model/Product/Gallery/GalleryManagement.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Catalog\Model\Product\Gallery;
88

9+
use Magento\AwsS3\Driver\AwsS3;
910
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
1011
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
1112
use Magento\Catalog\Api\ProductRepositoryInterface;
@@ -287,10 +288,18 @@ private function getImageContent($product, $entry): ImageContentInterface
287288
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
288289
$path = $mediaDirectory->getAbsolutePath($product->getMediaConfig()->getMediaPath($entry->getFile()));
289290
$fileName = $this->file->getPathInfo($path)['basename'];
290-
$imageFileContent = $mediaDirectory->getDriver()->fileGetContents($path);
291+
$fileDriver = $mediaDirectory->getDriver();
292+
$imageFileContent = $fileDriver->fileGetContents($path);
293+
294+
if ($fileDriver instanceof AwsS3) {
295+
$remoteMediaMimeType = $fileDriver->getMetadata($path);
296+
$mediaMimeType = $remoteMediaMimeType['mimetype'];
297+
} else {
298+
$mediaMimeType = $this->mime->getMimeType($path);
299+
}
291300
return $this->imageContentInterface->create()
292301
->setName($fileName)
293302
->setBase64EncodedData(base64_encode($imageFileContent))
294-
->setType($this->mime->getMimeType($path));
303+
->setType($mediaMimeType);
295304
}
296305
}

app/code/Magento/Catalog/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"magento/module-ui": "*",
3232
"magento/module-url-rewrite": "*",
3333
"magento/module-widget": "*",
34-
"magento/module-wishlist": "*"
34+
"magento/module-wishlist": "*",
35+
"magento/module-aws-s3": "*"
3536
},
3637
"suggest": {
3738
"magento/module-cookie": "*",

app/code/Magento/CatalogInventory/Model/Configuration.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
use Magento\Store\Model\ScopeInterface;
1414
use Magento\Store\Model\StoreManagerInterface;
1515

16-
/**
17-
* Class Configuration
18-
*/
1916
class Configuration implements StockConfigurationInterface, ResetAfterRequestInterface
2017
{
2118
/**

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ private function getSearch()
249249
/**
250250
* Test search.
251251
*
252-
* @deprecated 100.1.0 @see __construct
252+
* @deprecated 100.1.0
253+
* @see __construct
253254
* @param \Magento\Search\Api\SearchInterface $object
254255
* @return void
255256
* @since 100.1.0
@@ -276,7 +277,8 @@ private function getSearchCriteriaBuilder()
276277
/**
277278
* Set search criteria builder.
278279
*
279-
* @deprecated 100.1.0 @see __construct
280+
* @deprecated 100.1.0
281+
* @see __construct
280282
* @param \Magento\Framework\Api\Search\SearchCriteriaBuilder $object
281283
* @return void
282284
* @since 100.1.0
@@ -302,7 +304,8 @@ private function getFilterBuilder()
302304
/**
303305
* Set filter builder.
304306
*
305-
* @deprecated 100.1.0 @see __construct
307+
* @deprecated 100.1.0
308+
* @see __construct
306309
* @param \Magento\Framework\Api\FilterBuilder $object
307310
* @return void
308311
* @since 100.1.0

app/code/Magento/Eav/Model/ResourceModel/Attribute/Collection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* EAV additional attribute resource collection (Using Forms)
1212
*
13+
* phpcs:disable Magento2.Classes.AbstractApi.AbstractApi
1314
* @api
1415
* @since 100.0.2
1516
*/
@@ -67,7 +68,7 @@ public function __construct(
6768
/**
6869
* @inheritDoc
6970
*/
70-
public function _resetState(): void
71+
public function _resetState(): void //phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedFunction
7172
{
7273
/* Note: because Eav attribute loading takes significant performance,
7374
we are not resetting it like other collections. */

app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public function setSortOrder($direction = self::SORT_ORDER_ASC)
203203
*/
204204
protected function _beforeLoad()
205205
{
206+
$store = $this->getStore();
206207
$select = $this->getSelect();
207208
$connection = $this->getConnection();
208209
$entityType = $this->getEntityType();
@@ -264,7 +265,6 @@ protected function _beforeLoad()
264265
}
265266
}
266267

267-
$store = $this->getStore();
268268
$joinWebsiteExpression = $connection->quoteInto(
269269
'sa.attribute_id = main_table.attribute_id AND sa.website_id = ?',
270270
(int)$store->getWebsiteId()

app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\App\Action\HttpGetActionInterface;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\ImportExport\Model\Import;
1011

1112
/**
1213
* Download history controller
@@ -47,6 +48,7 @@ public function __construct(
4748
*/
4849
public function execute()
4950
{
51+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
5052
$fileName = basename($this->getRequest()->getParam('filename'));
5153

5254
/** @var \Magento\ImportExport\Helper\Report $reportHelper */
@@ -59,17 +61,12 @@ public function execute()
5961
return $resultRedirect;
6062
}
6163

62-
$this->fileFactory->create(
64+
return $this->fileFactory->create(
6365
$fileName,
64-
null,
66+
['type' => 'filename', 'value' => Import::IMPORT_HISTORY_DIR . $fileName],
6567
DirectoryList::VAR_IMPORT_EXPORT,
6668
'application/octet-stream',
6769
$reportHelper->getReportSize($fileName)
6870
);
69-
70-
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
71-
$resultRaw = $this->resultRawFactory->create();
72-
$resultRaw->setContents($reportHelper->getReportOutput($fileName));
73-
return $resultRaw;
7471
}
7572
}

app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/History/DownloadTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Backend\Model\View\Result\Redirect;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
1213
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\App\Response\Http\FileFactory;
15+
use Magento\Framework\App\ResponseInterface;
1416
use Magento\Framework\Controller\Result\Raw;
1517
use Magento\Framework\Controller\Result\RawFactory;
1618
use Magento\Framework\Controller\Result\RedirectFactory;
1719
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1820
use Magento\ImportExport\Controller\Adminhtml\History\Download;
1921
use Magento\ImportExport\Helper\Report;
22+
use Magento\ImportExport\Model\Import;
2023
use PHPUnit\Framework\MockObject\MockObject;
2124
use PHPUnit\Framework\TestCase;
2225

@@ -155,8 +158,20 @@ public function testExecute($requestFilename, $processedFilename)
155158
$this->reportHelper->method('importFileExists')
156159
->with($processedFilename)
157160
->willReturn(true);
158-
$this->resultRaw->expects($this->once())->method('setContents');
159-
$this->downloadController->execute();
161+
162+
$responseMock = $this->getMockBuilder(ResponseInterface::class)
163+
->getMock();
164+
$this->fileFactory->expects($this->once())
165+
->method('create')
166+
->with(
167+
$processedFilename,
168+
['type' => 'filename', 'value' =>Import::IMPORT_HISTORY_DIR . $processedFilename],
169+
DirectoryList::VAR_IMPORT_EXPORT,
170+
'application/octet-stream',
171+
1
172+
)
173+
->willReturn($responseMock);
174+
$this->assertSame($responseMock, $this->downloadController->execute());
160175
}
161176

162177
/**

0 commit comments

Comments
 (0)