Skip to content

Commit 1c5fb1b

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 review comments
1 parent 8dc171d commit 1c5fb1b

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,18 @@ public function launch(): ResponseInterface
216216
*/
217217
private function createLocalCopy(): void
218218
{
219-
$synchronizer = $this->syncFactory->create(['directory' => $this->directoryPub]);
220-
$synchronizer->synchronize($this->relativeFileName);
219+
$this->syncFactory->create(['directory' => $this->directoryPub])
220+
->synchronize($this->relativeFileName);
221221

222222
if ($this->directoryPub->isReadable($this->relativeFileName)) {
223223
return;
224224
}
225225

226226
if ($this->mediaUrlFormat === CatalogMediaConfig::HASH) {
227227
$this->imageResize->resizeFromImageName($this->getOriginalImage($this->relativeFileName));
228-
if (!$this->directoryPub->isReadable($this->relativeFileName)) {
229-
$synchronizer->synchronize($this->relativeFileName);
230-
}
228+
// if (!$this->directoryPub->isReadable($this->relativeFileName)) {
229+
// $synchronizer->synchronize($this->relativeFileName);
230+
// }
231231
}
232232
}
233233

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\MediaStorage\Model\File\Storage;
79

810
use Magento\Framework\Exception\FileSystemException;
911
use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWrite;
1012
use Magento\Framework\Filesystem\File\WriteInterface;
13+
1114
/**
12-
* Class Synchronization
15+
* Synchronize files from Db storage to local file system
1316
*/
1417
class Synchronization
1518
{

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
28
namespace Magento\MediaStorage\Model\File\Storage;
39

410
use Magento\Framework\ObjectManagerInterface;
@@ -13,25 +19,26 @@ class SynchronizationFactory
1319
*
1420
* @var ObjectManagerInterface
1521
*/
16-
protected $_objectManager = null;
22+
private $objectManager = null;
1723

1824
/**
1925
* Instance name to create
2026
*
2127
* @var string
2228
*/
23-
protected $_instanceName = null;
29+
private $instanceName = null;
2430

2531
/**
2632
* Factory constructor
2733
*
2834
* @param ObjectManagerInterface $objectManager
2935
* @param string $instanceName
3036
*/
31-
public function __construct(ObjectManagerInterface $objectManager, string $instanceName = '\\Magento\\MediaStorage\\Model\\File\\Storage\\Synchronization')
37+
public function __construct(ObjectManagerInterface $objectManager, string $instanceName =
38+
'\\Magento\\MediaStorage\\Model\\File\\Storage\\Synchronization')
3239
{
33-
$this->_objectManager = $objectManager;
34-
$this->_instanceName = $instanceName;
40+
$this->objectManager = $objectManager;
41+
$this->instanceName = $instanceName;
3542
}
3643

3744
/**
@@ -42,6 +49,6 @@ public function __construct(ObjectManagerInterface $objectManager, string $insta
4249
*/
4350
public function create(array $data = []): Synchronization
4451
{
45-
return $this->_objectManager->create($this->_instanceName, $data);
52+
return $this->objectManager->create($this->instanceName, $data);
4653
}
4754
}

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

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

810
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -15,7 +17,7 @@
1517
use Magento\RemoteStorage\Filesystem;
1618

1719
/**
18-
* Class Synchronization
20+
* Synchronize files from remote to local file system.
1921
*/
2022
class Synchronization
2123
{
@@ -43,8 +45,12 @@ class Synchronization
4345
public function __construct(Config $config, Filesystem $filesystem)
4446
{
4547
$this->isEnabled = $config->isEnabled();
46-
$this->remoteDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB, RemoteDriverPool::REMOTE);
47-
$this->localDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB, LocalDriverPool::FILE);
48+
$this->remoteDirectory = $filesystem->getDirectoryWrite(
49+
DirectoryList::PUB,
50+
RemoteDriverPool::REMOTE);
51+
$this->localDirectory = $filesystem->getDirectoryWrite(
52+
DirectoryList::PUB, LocalDriverPool::FILE
53+
);
4854
}
4955

5056
/**

app/code/Magento/RemoteStorage/Model/File/Storage/SynchronizationFactory.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
28
namespace Magento\RemoteStorage\Model\File\Storage;
39

10+
use Magento\Framework\ObjectManagerInterface;
411
use Magento\RemoteStorage\Model\Config;
12+
513
/**
614
* Factory class for @see \Magento\RemoteStorage\Model\File\Storage\Synchronization
715
*/
816
class SynchronizationFactory extends \Magento\MediaStorage\Model\File\Storage\SynchronizationFactory
917
{
1018
/**
11-
* @var bool
19+
* Object Manager instance
20+
*
21+
* @var ObjectManagerInterface
1222
*/
13-
private $isEnabled;
23+
private $objectManager = null;
24+
25+
/**
26+
* @var Config
27+
*/
28+
private $config;
1429

1530
/**
1631
* Factory constructor
1732
*
33+
* @param ObjectManagerInterface $objectManager
1834
* @param Config $config
1935
*/
20-
public function __construct( Config $config)
36+
public function __construct(ObjectManagerInterface $objectManager, Config $config)
2137
{
22-
$this->isEnabled = $config->isEnabled();
38+
$this->config = $config;
39+
parent::__construct($objectManager);
2340
}
2441

42+
/**
43+
* Create class instance with specified parameters
44+
*
45+
* @param array $data
46+
* @return \Magento\MediaStorage\Model\File\Storage\Synchronization|mixed
47+
* @throws \Magento\Framework\Exception\FileSystemException
48+
* @throws \Magento\Framework\Exception\RuntimeException
49+
*/
2550
public function create(array $data = [])
2651
{
27-
if ($this->isEnabled) {
28-
return $this->_objectManager->create(Synchronization::class, $data);
52+
if ($this->config->isEnabled()) {
53+
return $this->objectManager->create(Synchronization::class, $data);
2954
}
3055
return parent::create($data);
3156
}

0 commit comments

Comments
 (0)