Skip to content

Commit 2462490

Browse files
Roman HaninRoman Hanin
authored andcommitted
B2B-1610: Upgrade to Flysystem 2.0
- metadata and cache fix
1 parent 722b8b8 commit 2462490

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ public function createConfigured(
119119
$client = new S3Client($config);
120120
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $prefix);
121121
$cache = $this->cacheInterfaceFactory->create(
122-
$this->cachePrefix ? ['prefix' => $this->cachePrefix] : []
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+
]
123131
);
124132

125133
return $this->objectManager->create(
@@ -128,16 +136,12 @@ public function createConfigured(
128136
'adapter' => $this->cachedAdapterInterfaceFactory->create(
129137
[
130138
'adapter' => $adapter,
131-
'cache' => $cache
139+
'cache' => $cache,
140+
'metadataProvider' => $metadataProvider
132141
]
133142
),
134143
'objectUrl' => $client->getObjectUrl($config['bucket'], trim($prefix, '\\/') . '/.'),
135-
'metadataProvider' => $this->metadataProviderFactory->create(
136-
[
137-
'adapter' => $adapter,
138-
'cache' => $cache
139-
]
140-
),
144+
'metadataProvider' => $metadataProvider,
141145
]
142146
);
143147
}

app/code/Magento/RemoteStorage/Driver/Adapter/CachedAdapter.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class CachedAdapter implements CachedAdapterInterface
2727
*/
2828
private $cache;
2929

30-
/**
31-
* @var MetadataProviderInterfaceFactory
32-
*/
33-
private $metadataProviderFactory;
34-
3530
/**
3631
* @var MetadataProviderInterface
3732
*/
@@ -42,16 +37,16 @@ class CachedAdapter implements CachedAdapterInterface
4237
*
4338
* @param FilesystemAdapter $adapter
4439
* @param CacheInterface $cache
45-
* @param MetadataProviderInterfaceFactory $metadataProviderFactory
40+
* @param MetadataProviderInterface $metadataProvider
4641
*/
4742
public function __construct(
4843
FilesystemAdapter $adapter,
4944
CacheInterface $cache,
50-
MetadataProviderInterfaceFactory $metadataProviderFactory
45+
MetadataProviderInterface $metadataProvider
5146
) {
5247
$this->adapter = $adapter;
5348
$this->cache = $cache;
54-
$this->metadataProviderFactory = $metadataProviderFactory;
49+
$this->metadataProvider = $metadataProvider;
5550
}
5651

5752
/**
@@ -201,14 +196,6 @@ public function listContents(string $path, bool $deep): iterable
201196
*/
202197
private function getMetadata($path)
203198
{
204-
if (!$this->metadataProvider) {
205-
$this->metadataProvider = $this->metadataProviderFactory->create(
206-
[
207-
'adapter' => $this->adapter,
208-
'cache' => $this->cache
209-
]
210-
);
211-
}
212199
return $this->metadataProvider->getMetadata($path);
213200
}
214201

0 commit comments

Comments
 (0)