Skip to content

Commit 7aed4cd

Browse files
authored
Merge pull request #6768 from magento-arcticfoxes/2.4-develop-pr
[arcticfoxes] PRs
2 parents 9a68d68 + a9149dc commit 7aed4cd

34 files changed

+1732
-1474
lines changed

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

Lines changed: 188 additions & 99 deletions
Large diffs are not rendered by default.

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

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
namespace Magento\AwsS3\Driver;
99

1010
use Aws\S3\S3Client;
11-
use League\Flysystem\AwsS3v3\AwsS3Adapter;
12-
use League\Flysystem\Cached\CachedAdapter;
11+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
1312
use Magento\Framework\Exception\LocalizedException;
1413
use Magento\Framework\ObjectManagerInterface;
15-
use Magento\RemoteStorage\Driver\Cache\CacheFactory;
14+
use Magento\RemoteStorage\Driver\Adapter\Cache\CacheInterfaceFactory;
15+
use Magento\RemoteStorage\Driver\Adapter\CachedAdapterInterfaceFactory;
16+
use Magento\RemoteStorage\Driver\Adapter\MetadataProviderInterfaceFactory;
1617
use Magento\RemoteStorage\Driver\DriverException;
1718
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1819
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
@@ -29,25 +30,52 @@ class AwsS3Factory implements DriverFactoryInterface
2930
private $objectManager;
3031

3132
/**
32-
* @var CacheFactory
33+
* @var Config
3334
*/
34-
private $cacheFactory;
35+
private $config;
3536

3637
/**
37-
* @var Config
38+
* @var MetadataProviderInterfaceFactory
3839
*/
39-
private $config;
40+
private $metadataProviderFactory;
41+
42+
/**
43+
* @var CacheInterfaceFactory
44+
*/
45+
private $cacheInterfaceFactory;
46+
47+
/**
48+
* @var CachedAdapterInterfaceFactory
49+
*/
50+
private $cachedAdapterInterfaceFactory;
51+
52+
/**
53+
* @var string|null
54+
*/
55+
private $cachePrefix;
4056

4157
/**
4258
* @param ObjectManagerInterface $objectManager
43-
* @param CacheFactory $cacheFactory
4459
* @param Config $config
60+
* @param MetadataProviderInterfaceFactory $metadataProviderFactory
61+
* @param CacheInterfaceFactory $cacheInterfaceFactory
62+
* @param CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory
63+
* @param string|null $cachePrefix
4564
*/
46-
public function __construct(ObjectManagerInterface $objectManager, CacheFactory $cacheFactory, Config $config)
47-
{
65+
public function __construct(
66+
ObjectManagerInterface $objectManager,
67+
Config $config,
68+
MetadataProviderInterfaceFactory $metadataProviderFactory,
69+
CacheInterfaceFactory $cacheInterfaceFactory,
70+
CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory,
71+
string $cachePrefix = null
72+
) {
4873
$this->objectManager = $objectManager;
49-
$this->cacheFactory = $cacheFactory;
5074
$this->config = $config;
75+
$this->metadataProviderFactory = $metadataProviderFactory;
76+
$this->cacheInterfaceFactory = $cacheInterfaceFactory;
77+
$this->cachedAdapterInterfaceFactory = $cachedAdapterInterfaceFactory;
78+
$this->cachePrefix = $cachePrefix;
5179
}
5280

5381
/**
@@ -58,9 +86,7 @@ public function create(): RemoteDriverInterface
5886
try {
5987
return $this->createConfigured(
6088
$this->config->getConfig(),
61-
$this->config->getPrefix(),
62-
$this->config->getCacheAdapter(),
63-
$this->config->getCacheConfig()
89+
$this->config->getPrefix()
6490
);
6591
} catch (LocalizedException $exception) {
6692
throw new DriverException(__($exception->getMessage()), $exception);
@@ -73,8 +99,8 @@ public function create(): RemoteDriverInterface
7399
public function createConfigured(
74100
array $config,
75101
string $prefix,
76-
string $cacheAdapter,
77-
array $cacheConfig
102+
string $cacheAdapter = '',
103+
array $cacheConfig = []
78104
): RemoteDriverInterface {
79105
$config['version'] = 'latest';
80106

@@ -91,16 +117,31 @@ public function createConfigured(
91117
}
92118

93119
$client = new S3Client($config);
94-
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);
95-
120+
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $prefix);
121+
$cache = $this->cacheInterfaceFactory->create(
122+
// Custom cache prefix required to distinguish cache records for different sources.
123+
// phpcs:ignore Magento2.Security.InsecureFunction
124+
$this->cachePrefix ? ['prefix' => $this->cachePrefix] : ['prefix' => md5($config['bucket'] . $prefix)]
125+
);
126+
$metadataProvider = $this->metadataProviderFactory->create(
127+
[
128+
'adapter' => $adapter,
129+
'cache' => $cache
130+
]
131+
);
132+
$objectUrl = rtrim($client->getObjectUrl($config['bucket'], './'), '/') . trim($prefix, '\\/') . '/';
96133
return $this->objectManager->create(
97134
AwsS3::class,
98135
[
99-
'adapter' => $this->objectManager->create(CachedAdapter::class, [
100-
'adapter' => $adapter,
101-
'cache' => $this->cacheFactory->create($cacheAdapter, $cacheConfig)
102-
]),
103-
'objectUrl' => $client->getObjectUrl($adapter->getBucket(), $adapter->applyPathPrefix('.'))
136+
'adapter' => $this->cachedAdapterInterfaceFactory->create(
137+
[
138+
'adapter' => $adapter,
139+
'cache' => $cache,
140+
'metadataProvider' => $metadataProvider
141+
]
142+
),
143+
'objectUrl' => $objectUrl,
144+
'metadataProvider' => $metadataProvider,
104145
]
105146
);
106147
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AwsS3\Test\Mftf\Helper;
9+
10+
/**
11+
* Cache mock for metadata provider.
12+
*/
13+
class DummyMetadataCache implements \Magento\RemoteStorage\Driver\Adapter\Cache\CacheInterface
14+
{
15+
/**
16+
* @inheirtDoc
17+
*/
18+
public function exists(string $path): ?bool
19+
{
20+
return null;
21+
}
22+
23+
/**
24+
* @inheirtDoc
25+
*/
26+
public function getMetadata(string $path): ?array
27+
{
28+
return null;
29+
}
30+
31+
/**
32+
* @inheirtDoc
33+
*/
34+
public function flushCache(): void
35+
{
36+
}
37+
38+
/**
39+
* @inheirtDoc
40+
*/
41+
public function purgeQueue(): void
42+
{
43+
}
44+
45+
/**
46+
* @inheirtDoc
47+
*/
48+
public function moveFile(string $path, string $newpath): void
49+
{
50+
}
51+
52+
/**
53+
* @inheirtDoc
54+
*/
55+
public function copyFile(string $path, string $newpath): void
56+
{
57+
}
58+
59+
/**
60+
* @inheirtDoc
61+
*/
62+
public function deleteFile(string $path): void
63+
{
64+
}
65+
66+
/**
67+
* @inheirtDoc
68+
*/
69+
public function deleteDir(string $dirname): void
70+
{
71+
}
72+
73+
/**
74+
* @inheirtDoc
75+
*/
76+
public function updateMetadata(string $path, array $objectMetadata, bool $persist = false): void
77+
{
78+
}
79+
80+
/**
81+
* @inheirtDoc
82+
*/
83+
public function storeFileNotExists(string $path): void
84+
{
85+
}
86+
}

app/code/Magento/AwsS3/Test/Mftf/Helper/S3FileAssertions.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
use Aws\S3\S3Client;
1111
use Codeception\Lib\ModuleContainer;
12-
use League\Flysystem\AwsS3v3\AwsS3Adapter;
12+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
13+
use League\Flysystem\PathPrefixer;
1314
use Magento\AwsS3\Driver\AwsS3;
1415
use Magento\FunctionalTestingFramework\Helper\Helper;
1516
use Magento\Framework\Filesystem\DriverInterface;
17+
use Magento\RemoteStorage\Driver\Adapter\MetadataProvider;
1618

1719
/**
1820
* Class for MFTF helpers for doing file assertions using S3.
@@ -56,9 +58,11 @@ public function __construct(ModuleContainer $moduleContainer, ?array $config = n
5658
}
5759

5860
$client = new S3Client($config);
59-
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);
60-
$objectUrl = $client->getObjectUrl($adapter->getBucket(), $adapter->applyPathPrefix('.'));
61-
$s3Driver = new AwsS3($adapter, new MockTestLogger(), $objectUrl);
61+
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $prefix);
62+
$prefixer = new PathPrefixer($prefix);
63+
$objectUrl = $client->getObjectUrl($config['bucket'], ltrim($prefixer->prefixPath('.'), '/'));
64+
$metadataProvider = new MetadataProvider($adapter, new DummyMetadataCache());
65+
$s3Driver = new AwsS3($adapter, new MockTestLogger(), $objectUrl, $metadataProvider);
6266

6367
$this->driver = $s3Driver;
6468
}

0 commit comments

Comments
 (0)