Skip to content

Commit 330d595

Browse files
Merge branch '2.4-develop' into 21853
2 parents 922e029 + 26acabe commit 330d595

File tree

181 files changed

+5445
-1080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+5445
-1080
lines changed

app/code/Magento/AwsS3/Driver/AwsS3.php

+107-71
Large diffs are not rendered by default.

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

+45-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
use Aws\S3\S3Client;
1111
use League\Flysystem\AwsS3v3\AwsS3Adapter;
12+
use League\Flysystem\Cached\CachedAdapter;
13+
use Magento\Framework\Exception\LocalizedException;
1214
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\RemoteStorage\Driver\Cache\CacheFactory;
1316
use Magento\RemoteStorage\Driver\DriverException;
1417
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1518
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
19+
use Magento\RemoteStorage\Model\Config;
1620

1721
/**
1822
* Creates a pre-configured instance of AWS S3 driver.
@@ -24,19 +28,54 @@ class AwsS3Factory implements DriverFactoryInterface
2428
*/
2529
private $objectManager;
2630

31+
/**
32+
* @var CacheFactory
33+
*/
34+
private $cacheFactory;
35+
36+
/**
37+
* @var Config
38+
*/
39+
private $config;
40+
2741
/**
2842
* @param ObjectManagerInterface $objectManager
43+
* @param CacheFactory $cacheFactory
44+
* @param Config $config
2945
*/
30-
public function __construct(ObjectManagerInterface $objectManager)
46+
public function __construct(ObjectManagerInterface $objectManager, CacheFactory $cacheFactory, Config $config)
3147
{
3248
$this->objectManager = $objectManager;
49+
$this->cacheFactory = $cacheFactory;
50+
$this->config = $config;
3351
}
3452

3553
/**
3654
* @inheritDoc
3755
*/
38-
public function create(array $config, string $prefix): RemoteDriverInterface
56+
public function create(): RemoteDriverInterface
3957
{
58+
try {
59+
return $this->createConfigured(
60+
$this->config->getConfig(),
61+
$this->config->getPrefix(),
62+
$this->config->getCacheAdapter(),
63+
$this->config->getCacheConfig()
64+
);
65+
} catch (LocalizedException $exception) {
66+
throw new DriverException(__($exception->getMessage()), $exception);
67+
}
68+
}
69+
70+
/**
71+
* @inheritDoc
72+
*/
73+
public function createConfigured(
74+
array $config,
75+
string $prefix,
76+
string $cacheAdapter,
77+
array $cacheConfig
78+
): RemoteDriverInterface {
4079
$config['version'] = 'latest';
4180

4281
if (empty($config['credentials']['key']) || empty($config['credentials']['secret'])) {
@@ -53,7 +92,10 @@ public function create(array $config, string $prefix): RemoteDriverInterface
5392
return $this->objectManager->create(
5493
AwsS3::class,
5594
[
56-
'adapter' => $adapter,
95+
'adapter' => $this->objectManager->create(CachedAdapter::class, [
96+
'adapter' => $adapter,
97+
'cache' => $this->cacheFactory->create($cacheAdapter, $cacheConfig)
98+
]),
5799
'objectUrl' => $client->getObjectUrl($adapter->getBucket(), $adapter->applyPathPrefix('.'))
58100
]
59101
);

app/code/Magento/AwsS3/Test/Unit/Driver/AwsS3Test.php

+64-22
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\AwsS3\Test\Unit\Driver;
99

10+
use League\Flysystem\AdapterInterface;
1011
use League\Flysystem\AwsS3v3\AwsS3Adapter;
11-
use League\Flysystem\Cached\CachedAdapter;
1212
use Magento\AwsS3\Driver\AwsS3;
1313
use Magento\Framework\Exception\FileSystemException;
1414
use PHPUnit\Framework\MockObject\MockObject;
@@ -37,7 +37,7 @@ class AwsS3Test extends TestCase
3737
*/
3838
protected function setUp(): void
3939
{
40-
$this->adapterMock = $this->createMock(CachedAdapter::class);
40+
$this->adapterMock = $this->getMockForAbstractClass(AdapterInterface::class);
4141
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
4242

4343
$this->driver = new AwsS3($this->adapterMock, $loggerMock, self::URL);
@@ -101,11 +101,6 @@ public function getAbsolutePathDataProvider(): array
101101
'test.txt',
102102
self::URL . 'test/test.txt'
103103
],
104-
[
105-
self::URL . 'media/',
106-
'media/image.jpg',
107-
self::URL . 'media/image.jpg'
108-
],
109104
[
110105
self::URL . 'media/',
111106
'/catalog/test.png',
@@ -140,6 +135,26 @@ public function getAbsolutePathDataProvider(): array
140135
self::URL . 'var/import/images/product_images/',
141136
self::URL . 'var/import/images/product_images/1.png',
142137
self::URL . 'var/import/images/product_images/1.png'
138+
],
139+
[
140+
self::URL . 'var/import/images/product_images/1.png',
141+
'',
142+
self::URL . 'var/import/images/product_images/1.png'
143+
],
144+
[
145+
self::URL . 'media/',
146+
'',
147+
self::URL . 'media/',
148+
],
149+
[
150+
self::URL . 'media/',
151+
self::URL . 'media',
152+
self::URL . 'media',
153+
],
154+
[
155+
self::URL,
156+
'',
157+
self::URL
143158
]
144159
];
145160
}
@@ -170,7 +185,7 @@ public function getRelativePathDataProvider(): array
170185
[
171186
'',
172187
'/test/test.txt',
173-
'test/test.txt'
188+
'/test/test.txt'
174189
],
175190
[
176191
self::URL,
@@ -216,14 +231,14 @@ public function isDirectoryDataProvider(): array
216231
return [
217232
[
218233
'some_directory/',
219-
'some_directory/',
234+
'some_directory',
220235
false,
221236
[],
222237
false
223238
],
224239
[
225240
'some_directory',
226-
'some_directory/',
241+
'some_directory',
227242
true,
228243
[
229244
'type' => AwsS3::TYPE_DIR
@@ -232,7 +247,7 @@ public function isDirectoryDataProvider(): array
232247
],
233248
[
234249
self::URL . 'some_directory',
235-
'some_directory/',
250+
'some_directory',
236251
true,
237252
[
238253
'type' => AwsS3::TYPE_DIR
@@ -241,7 +256,7 @@ public function isDirectoryDataProvider(): array
241256
],
242257
[
243258
self::URL . 'some_directory',
244-
'some_directory/',
259+
'some_directory',
245260
true,
246261
[
247262
'type' => AwsS3::TYPE_FILE
@@ -391,12 +406,12 @@ public function getRealPathSafetyDataProvider(): array
391406
public function testSearchDirectory(): void
392407
{
393408
$expression = '/*';
394-
$path = 'path/';
409+
$path = 'path';
395410
$subPaths = [
396-
['path' => 'path/1'],
397-
['path' => 'path/2']
411+
['path' => 'path/1', 'dirname' => self::URL],
412+
['path' => 'path/2', 'dirname' => self::URL]
398413
];
399-
$expectedResult = ['path/1', 'path/2'];
414+
$expectedResult = [self::URL . 'path/1', self::URL . 'path/2'];
400415
$this->adapterMock->expects(self::atLeastOnce())->method('has')
401416
->willReturnMap([
402417
[$path, true]
@@ -405,8 +420,10 @@ public function testSearchDirectory(): void
405420
->willReturnMap([
406421
[$path, ['type' => AwsS3::TYPE_DIR]]
407422
]);
408-
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')->with($path, false)
423+
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')
424+
->with($path, false)
409425
->willReturn($subPaths);
426+
410427
self::assertEquals($expectedResult, $this->driver->search($expression, $path));
411428
}
412429

@@ -415,13 +432,13 @@ public function testSearchDirectory(): void
415432
*/
416433
public function testSearchFiles(): void
417434
{
418-
$expression = "/*";
419-
$path = 'path/';
435+
$expression = '/*';
436+
$path = 'path';
420437
$subPaths = [
421-
['path' => 'path/1.jpg'],
422-
['path' => 'path/2.png']
438+
['path' => 'path/1.jpg', 'dirname' => self::URL],
439+
['path' => 'path/2.png', 'dirname' => self::URL]
423440
];
424-
$expectedResult = ['path/1.jpg', 'path/2.png'];
441+
$expectedResult = [self::URL . 'path/1.jpg', self::URL . 'path/2.png'];
425442

426443
$this->adapterMock->expects(self::atLeastOnce())->method('has')
427444
->willReturnMap([
@@ -433,6 +450,31 @@ public function testSearchFiles(): void
433450
]);
434451
$this->adapterMock->expects(self::atLeastOnce())->method('listContents')->with($path, false)
435452
->willReturn($subPaths);
453+
436454
self::assertEquals($expectedResult, $this->driver->search($expression, $path));
437455
}
456+
457+
/**
458+
* @throws FileSystemException
459+
*/
460+
public function testCreateDirectory(): void
461+
{
462+
$this->adapterMock->expects(self::exactly(2))
463+
->method('has')
464+
->willReturnMap([
465+
['test', true],
466+
['test/test2', false]
467+
]);
468+
$this->adapterMock->expects(self::once())
469+
->method('getMetadata')
470+
->willReturnMap([
471+
['test', ['type' => AwsS3::TYPE_DIR]]
472+
]);
473+
$this->adapterMock->expects(self::once())
474+
->method('createDir')
475+
->with('test/test2')
476+
->willReturn(true);
477+
478+
self::assertTrue($this->driver->createDirectory(self::URL . 'test/test2/'));
479+
}
438480
}

app/code/Magento/Backend/Model/Dashboard/Period.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public function getDatePeriods(): array
4646
public function getPeriodChartUnits(): array
4747
{
4848
return [
49-
static::PERIOD_24_HOURS => static::PERIOD_UNIT_HOUR,
50-
static::PERIOD_7_DAYS => static::PERIOD_UNIT_DAY,
51-
static::PERIOD_1_MONTH => static::PERIOD_UNIT_DAY,
52-
static::PERIOD_1_YEAR => static::PERIOD_UNIT_MONTH,
53-
static::PERIOD_2_YEARS => static::PERIOD_UNIT_MONTH
49+
static::PERIOD_24_HOURS => self::PERIOD_UNIT_HOUR,
50+
static::PERIOD_7_DAYS => self::PERIOD_UNIT_DAY,
51+
static::PERIOD_1_MONTH => self::PERIOD_UNIT_DAY,
52+
static::PERIOD_1_YEAR => self::PERIOD_UNIT_MONTH,
53+
static::PERIOD_2_YEARS => self::PERIOD_UNIT_MONTH
5454
];
5555
}
5656
}

app/code/Magento/Backend/ViewModel/ChartDisabled.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
public function getConfigUrl(): string
5858
{
5959
return $this->urlBuilder->getUrl(
60-
static::ROUTE_SYSTEM_CONFIG,
60+
self::ROUTE_SYSTEM_CONFIG,
6161
['section' => 'admin', '_fragment' => 'admin_dashboard-link']
6262
);
6363
}
@@ -70,7 +70,7 @@ public function getConfigUrl(): string
7070
public function isChartEnabled(): bool
7171
{
7272
return $this->scopeConfig->isSetFlag(
73-
static::XML_PATH_ENABLE_CHARTS,
73+
self::XML_PATH_ENABLE_CHARTS,
7474
ScopeInterface::SCOPE_STORE
7575
);
7676
}

app/code/Magento/Backend/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"magento/module-backup": "*",
1111
"magento/module-catalog": "*",
1212
"magento/module-config": "*",
13+
"magento/module-cms": "*",
1314
"magento/module-customer": "*",
1415
"magento/module-developer": "*",
1516
"magento/module-directory": "*",

app/code/Magento/Bundle/Model/Plugin/Frontend/Product.php renamed to app/code/Magento/Bundle/Model/Plugin/Frontend/ProductIdentitiesExtender.php

+29-6
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@
77

88
namespace Magento\Bundle\Model\Plugin\Frontend;
99

10-
use Magento\Bundle\Model\Product\Type;
10+
use Magento\Bundle\Model\Product\Type as BundleType;
1111
use Magento\Catalog\Model\Product as CatalogProduct;
1212

1313
/**
1414
* Add child identities to product identities on storefront.
1515
*/
16-
class Product
16+
class ProductIdentitiesExtender
1717
{
1818
/**
19-
* @var Type
19+
* @var BundleType
2020
*/
2121
private $type;
2222

2323
/**
24-
* @param Type $type
24+
* @var array
2525
*/
26-
public function __construct(Type $type)
26+
private $cacheChildrenIds = [];
27+
28+
/**
29+
* @param BundleType $type
30+
*/
31+
public function __construct(BundleType $type)
2732
{
2833
$this->type = $type;
2934
}
@@ -37,12 +42,30 @@ public function __construct(Type $type)
3742
*/
3843
public function afterGetIdentities(CatalogProduct $product, array $identities): array
3944
{
40-
foreach ($this->type->getChildrenIds($product->getEntityId()) as $childIds) {
45+
if ($product->getTypeId() !== BundleType::TYPE_CODE) {
46+
return $identities;
47+
}
48+
foreach ($this->getChildrenIds($product->getEntityId()) as $childIds) {
4149
foreach ($childIds as $childId) {
4250
$identities[] = CatalogProduct::CACHE_TAG . '_' . $childId;
4351
}
4452
}
4553

4654
return array_unique($identities);
4755
}
56+
57+
/**
58+
* Get children ids with cache use
59+
*
60+
* @param mixed $entityId
61+
* @return array
62+
*/
63+
private function getChildrenIds($entityId): array
64+
{
65+
if (!isset($this->cacheChildrenIds[$entityId])) {
66+
$this->cacheChildrenIds[$entityId] = $this->type->getChildrenIds($entityId);
67+
}
68+
69+
return $this->cacheChildrenIds[$entityId];
70+
}
4871
}

0 commit comments

Comments
 (0)