Skip to content

Commit 8dc171d

Browse files
committed
B2B-1789: First Request For Storefront Image After Deleting Local File System Cached Images Results In Magento Placeholder Image When Using S3 -
Added new sync for remote storage
1 parent c068774 commit 8dc171d

File tree

5 files changed

+87
-20
lines changed

5 files changed

+87
-20
lines changed

app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use Magento\Framework\Exception\FileSystemException;
99
use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWrite;
1010
use Magento\Framework\Filesystem\File\WriteInterface;
11-
use Magento\MediaStorage\Service\ImageResize;
12-
use Magento\MediaStorage\Model\File\Storage\Database;
13-
1411
/**
1512
* Class Synchronization
1613
*/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace Magento\MediaStorage\Model\File\Storage;
3+
4+
use Magento\Framework\ObjectManagerInterface;
5+
6+
/**
7+
* Factory class for @see \Magento\MediaStorage\Model\File\Storage\Synchronization
8+
*/
9+
class SynchronizationFactory
10+
{
11+
/**
12+
* Object Manager instance
13+
*
14+
* @var ObjectManagerInterface
15+
*/
16+
protected $_objectManager = null;
17+
18+
/**
19+
* Instance name to create
20+
*
21+
* @var string
22+
*/
23+
protected $_instanceName = null;
24+
25+
/**
26+
* Factory constructor
27+
*
28+
* @param ObjectManagerInterface $objectManager
29+
* @param string $instanceName
30+
*/
31+
public function __construct(ObjectManagerInterface $objectManager, string $instanceName = '\\Magento\\MediaStorage\\Model\\File\\Storage\\Synchronization')
32+
{
33+
$this->_objectManager = $objectManager;
34+
$this->_instanceName = $instanceName;
35+
}
36+
37+
/**
38+
* Create class instance with specified parameters
39+
*
40+
* @param array $data
41+
* @return Synchronization
42+
*/
43+
public function create(array $data = []): Synchronization
44+
{
45+
return $this->_objectManager->create($this->_instanceName, $data);
46+
}
47+
}

app/code/Magento/RemoteStorage/Plugin/MediaStorage.php renamed to app/code/Magento/RemoteStorage/Model/File/Storage/Synchronization.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
7-
8-
namespace Magento\RemoteStorage\Plugin;
6+
namespace Magento\RemoteStorage\Model\File\Storage;
97

108
use Magento\Framework\App\Filesystem\DirectoryList;
119
use Magento\Framework\Exception\FileSystemException;
1210
use Magento\Framework\Exception\RuntimeException;
13-
use Magento\Framework\Exception\ValidatorException;
1411
use Magento\Framework\Filesystem\Directory\WriteInterface;
15-
use Magento\MediaStorage\Model\File\Storage\Synchronization;
1612
use Magento\RemoteStorage\Driver\DriverPool as RemoteDriverPool;
1713
use Magento\Framework\Filesystem\DriverPool as LocalDriverPool;
1814
use Magento\RemoteStorage\Model\Config;
1915
use Magento\RemoteStorage\Filesystem;
2016

2117
/**
22-
* Modifies the base URL.
18+
* Class Synchronization
2319
*/
24-
class MediaStorage
20+
class Synchronization
2521
{
2622
/**
2723
* @var bool
@@ -52,16 +48,13 @@ public function __construct(Config $config, Filesystem $filesystem)
5248
}
5349

5450
/**
55-
* Download remote file
51+
* Synchronize file
5652
*
57-
* @param Synchronization $subject
5853
* @param string $relativeFileName
59-
* @return null
60-
* @throws FileSystemException
61-
* @throws ValidatorException
62-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54+
* @return void
55+
* @throws \LogicException
6356
*/
64-
public function beforeSynchronize(Synchronization $subject, string $relativeFileName): void
57+
public function synchronize($relativeFileName)
6558
{
6659
if ($this->isEnabled && $this->remoteDirectory->isExist($relativeFileName)) {
6760
$file = $this->localDirectory->openFile($relativeFileName, 'w');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace Magento\RemoteStorage\Model\File\Storage;
3+
4+
use Magento\RemoteStorage\Model\Config;
5+
/**
6+
* Factory class for @see \Magento\RemoteStorage\Model\File\Storage\Synchronization
7+
*/
8+
class SynchronizationFactory extends \Magento\MediaStorage\Model\File\Storage\SynchronizationFactory
9+
{
10+
/**
11+
* @var bool
12+
*/
13+
private $isEnabled;
14+
15+
/**
16+
* Factory constructor
17+
*
18+
* @param Config $config
19+
*/
20+
public function __construct( Config $config)
21+
{
22+
$this->isEnabled = $config->isEnabled();
23+
}
24+
25+
public function create(array $data = [])
26+
{
27+
if ($this->isEnabled) {
28+
return $this->_objectManager->create(Synchronization::class, $data);
29+
}
30+
return parent::create($data);
31+
}
32+
}

app/code/Magento/RemoteStorage/etc/di.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<preference for="Magento\RemoteStorage\Driver\Adapter\CachedAdapterInterface" type="Magento\RemoteStorage\Driver\Adapter\CachedAdapter"/>
1111
<preference for="Magento\RemoteStorage\Driver\Adapter\MetadataProviderInterface" type="Magento\RemoteStorage\Driver\Adapter\MetadataProvider"/>
1212
<preference for="Magento\RemoteStorage\Driver\Adapter\MetadataProviderFactoryInterface" type="Magento\RemoteStorage\Driver\Adapter\MetadataProviderFactory"/>
13+
<preference for="Magento\MediaStorage\Model\File\Storage\SynchronizationFactory" type="Magento\RemoteStorage\Model\File\Storage\SynchronizationFactory"/>
1314
<virtualType name="remoteWriteFactory" type="Magento\Framework\Filesystem\Directory\WriteFactory">
1415
<arguments>
1516
<argument name="driverPool" xsi:type="object">Magento\RemoteStorage\Driver\DriverPool</argument>
@@ -75,9 +76,6 @@
7576
<argument name="filesystem" xsi:type="object">fullRemoteFilesystem</argument>
7677
</arguments>
7778
</type>
78-
<type name="Magento\MediaStorage\Model\File\Storage\Synchronization">
79-
<plugin name="remoteMedia" type="Magento\RemoteStorage\Plugin\MediaStorage" />
80-
</type>
8179
<type name="Magento\Framework\Data\Collection\Filesystem">
8280
<arguments>
8381
<argument name="filesystem" xsi:type="object">fullRemoteFilesystem</argument>

0 commit comments

Comments
 (0)