Skip to content

Commit eff966c

Browse files
merge magento-commerce/2.4-develop into magento-honey-badgers/MC-37484-cart-query
2 parents ddce888 + 3835860 commit eff966c

File tree

15 files changed

+164
-15
lines changed

15 files changed

+164
-15
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AwsS3StorefrontCaptchaOnCustomerLoginTest" extends="StorefrontCaptchaOnCustomerLoginTest">
12+
<annotations>
13+
<features value="Captcha"/>
14+
<stories value="Login with Customer Account + Captcha"/>
15+
<title value="AWS S3 Captcha customer login page test"/>
16+
<description value="Check CAPTCHA on Storefront Login Page."/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-39491" />
19+
<group value="remote_storage_aws_s3"/>
20+
</annotations>
21+
<before>
22+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage"/>
23+
</before>
24+
<after>
25+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage"/>
26+
</after>
27+
</test>
28+
</tests>

app/code/Magento/AwsS3/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "magento/module-aws-s-3",
2+
"name": "magento/module-aws-s3",
33
"description": "N/A",
44
"config": {
55
"sort-packages": true

app/code/Magento/Captcha/Helper/Data.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public function getFonts()
150150
*/
151151
public function getImgDir($website = null)
152152
{
153-
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
153+
// Captcha images are not re-used and should be stored only locally.
154+
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA, Filesystem\DriverPool::FILE);
154155
$captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
155156
$mediaDir->create($captchaDir);
156157
return $mediaDir->getAbsolutePath($captchaDir) . '/';

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ protected function prepareSelectsByRange(
430430
$field,
431431
$select,
432432
$range,
433-
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
433+
\Magento\Framework\DB\Query\BatchIteratorInterface::UNIQUE_FIELD_ITERATOR
434434
);
435435

436436
$queries = [];

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,58 @@ protected function _productLimitationJoinPrice()
2525
$this->_productLimitationFilters->setUsePriceIndex(false);
2626
return $this->_productLimitationPrice(true);
2727
}
28+
29+
/**
30+
* Return approximately amount if too much entities.
31+
*
32+
* @return int|mixed
33+
*/
34+
public function getSize()
35+
{
36+
$sql = $this->getSelectCountSql();
37+
$possibleCount = $this->analyzeCount($sql);
38+
39+
if ($possibleCount > 20000) {
40+
return $possibleCount;
41+
}
42+
43+
return parent::getSize();
44+
}
45+
46+
/**
47+
* Analyze amount of entities in DB.
48+
*
49+
* @param $sql
50+
* @return int|mixed
51+
* @throws \Zend_Db_Statement_Exception
52+
*/
53+
private function analyzeCount($sql)
54+
{
55+
$results = $this->getConnection()->query('EXPLAIN ' . $sql)->fetchAll();
56+
$alias = $this->getMainTableAlias();
57+
58+
foreach ($results as $result) {
59+
if ($result['table'] == $alias) {
60+
return $result['rows'];
61+
}
62+
}
63+
64+
return 0;
65+
}
66+
67+
/**
68+
* Identify main table alias or its name if alias is not defined.
69+
*
70+
* @return string
71+
* @throws \LogicException
72+
*/
73+
private function getMainTableAlias()
74+
{
75+
foreach ($this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM) as $tableAlias => $tableMetadata) {
76+
if ($tableMetadata['joinType'] == 'from') {
77+
return $tableAlias;
78+
}
79+
}
80+
throw new \LogicException("Main table cannot be identified.");
81+
}
2882
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ private function getAlreadyExistedImage(array $imageRow, string $columnImage, st
19651965
if (filter_var($columnImage, FILTER_VALIDATE_URL)) {
19661966
$hash = $this->getFileHash($columnImage);
19671967
} else {
1968-
$path = $importDir . DS . $columnImage;
1968+
$path = $importDir . DIRECTORY_SEPARATOR . $columnImage;
19691969
$hash = $this->isFileExists($path) ? $this->getFileHash($path) : '';
19701970
}
19711971

@@ -1991,7 +1991,7 @@ function ($exists, $file) use ($hash) {
19911991
private function addImageHashes(array &$images): void
19921992
{
19931993
$productMediaPath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)
1994-
->getAbsolutePath(DS . 'catalog' . DS . 'product');
1994+
->getAbsolutePath(DIRECTORY_SEPARATOR . 'catalog' . DIRECTORY_SEPARATOR . 'product');
19951995

19961996
foreach ($images as $storeId => $skus) {
19971997
foreach ($skus as $sku => $files) {
@@ -2188,7 +2188,7 @@ private function getImportDir(): string
21882188
$dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH];
21892189

21902190
return empty($this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR])
2191-
? $dirAddon . DS . $this->_mediaDirectory->getRelativePath('import')
2191+
? $dirAddon . DIRECTORY_SEPARATOR . $this->_mediaDirectory->getRelativePath('import')
21922192
: $this->_parameters[Import::FIELD_NAME_IMG_FILE_DIR];
21932193
}
21942194

app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@ public function execute($ids = null): void
149149

150150
$select = $connection->select();
151151
$select->distinct(true);
152-
$select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
152+
$select->from(
153+
[
154+
'e' => $entityMetadata->getEntityTable()
155+
],
156+
$entityMetadata->getIdentifierField()
157+
)->where(
158+
'type_id = ?',
159+
$indexer->getTypeId()
160+
);
153161

154162
$batchQueries = $this->batchQueryGenerator->generate(
155163
$entityMetadata->getIdentifierField(),
156164
$select,
157165
$batchRowCount,
158-
BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
166+
BatchIteratorInterface::UNIQUE_FIELD_ITERATOR
159167
);
160168

161169
foreach ($batchQueries as $query) {

app/code/Magento/MediaStorage/App/Media.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ public function launch(): ResponseInterface
187187
$this->mediaDirectoryPath = $config->getMediaDirectory();
188188
$allowedResources = $config->getAllowedResources();
189189
$isAllowed = $this->isAllowed;
190-
if (!$isAllowed($this->relativeFileName, $allowedResources)) {
190+
$fileAbsolutePath = $this->directoryPub->getAbsolutePath($this->relativeFileName);
191+
$fileRelativePath = str_replace(rtrim($this->mediaDirectoryPath, '/') . '/', '', $fileAbsolutePath);
192+
if (!$isAllowed($fileRelativePath, $allowedResources)) {
191193
throw new LogicException('The path is not allowed: ' . $this->relativeFileName);
192194
}
193195
}

app/code/Magento/MediaStorage/Test/Unit/App/MediaTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testProcessRequestCreatesConfigFileMediaDirectoryIsNotProvided()
118118
->method('getAbsolutePath')
119119
->with(null)
120120
->willReturn(self::MEDIA_DIRECTORY);
121-
$this->directoryPubMock->expects(self::once())
121+
$this->directoryPubMock->expects(self::exactly(2))
122122
->method('getAbsolutePath')
123123
->with(self::RELATIVE_FILE_PATH)
124124
->willReturn($filePath);
@@ -154,7 +154,7 @@ public function testProcessRequestReturnsFileIfItsProperlySynchronized(): void
154154
->method('isReadable')
155155
->with(self::RELATIVE_FILE_PATH)
156156
->willReturn(true);
157-
$this->directoryPubMock->expects(self::once())
157+
$this->directoryPubMock->expects(self::exactly(2))
158158
->method('getAbsolutePath')
159159
->with(self::RELATIVE_FILE_PATH)
160160
->willReturn($filePath);
@@ -214,10 +214,15 @@ public function testCatchException(bool $isDeveloper, int $setBodyCalls): void
214214

215215
public function testExceptionWhenIsAllowedReturnsFalse(): void
216216
{
217+
$filePath = '/absolute/path/to/test/file.png';
217218
$this->directoryMediaMock->expects(self::once())
218219
->method('getAbsolutePath')
219220
->with(null)
220221
->willReturn(self::MEDIA_DIRECTORY);
222+
$this->directoryPubMock->expects(self::once())
223+
->method('getAbsolutePath')
224+
->with(self::RELATIVE_FILE_PATH)
225+
->willReturn($filePath);
221226
$this->configMock->expects(self::once())
222227
->method('save');
223228

app/code/Magento/RemoteStorage/Driver/Cache/CacheFactory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
namespace Magento\RemoteStorage\Driver\Cache;
99

10+
use League\Flysystem\Adapter\Local;
1011
use League\Flysystem\Cached\CacheInterface;
1112
use League\Flysystem\Cached\Storage\Memory;
1213
use League\Flysystem\Cached\Storage\Predis;
14+
use League\Flysystem\Cached\Storage\Adapter;
15+
use Magento\Framework\App\Filesystem\DirectoryList;
16+
use Magento\Framework\Filesystem;
1317
use Magento\RemoteStorage\Driver\DriverException;
18+
use Magento\RemoteStorage\Driver\DriverPool;
1419
use Predis\Client;
1520

1621
/**
@@ -20,14 +25,32 @@ class CacheFactory
2025
{
2126
public const ADAPTER_PREDIS = 'predis';
2227
public const ADAPTER_MEMORY = 'memory';
28+
public const ADAPTER_LOCAL = 'local';
2329

2430
private const CACHE_KEY = 'storage';
31+
private const CACHE_FILE = 'storage_cache.json';
2532

2633
/**
2734
* Cache for 30 days.
2835
*/
2936
private const CACHE_EXPIRATION = 30 * 86400;
3037

38+
/**
39+
* @var string
40+
*/
41+
private $localCacheRoot;
42+
43+
/**
44+
* @param Filesystem $filesystem
45+
*/
46+
public function __construct(Filesystem $filesystem)
47+
{
48+
$this->localCacheRoot = $filesystem->getDirectoryRead(
49+
DirectoryList::VAR_DIR,
50+
DriverPool::FILE
51+
)->getAbsolutePath();
52+
}
53+
3154
/**
3255
* Create cache adapter.
3356
*
@@ -47,6 +70,8 @@ public function create(string $adapter, array $config = []): CacheInterface
4770
return new Predis(new Client($config), self::CACHE_KEY, self::CACHE_EXPIRATION);
4871
case self::ADAPTER_MEMORY:
4972
return new Memory();
73+
case self::ADAPTER_LOCAL:
74+
return new Adapter(new Local($this->localCacheRoot), self::CACHE_FILE, self::CACHE_EXPIRATION);
5075
}
5176

5277
throw new DriverException(__('Cache adapter %1 is not supported', $adapter));

0 commit comments

Comments
 (0)