Skip to content

Commit

Permalink
Magento Fork initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 10, 2021
1 parent 149fb50 commit 4bf1800
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 52 deletions.
4 changes: 1 addition & 3 deletions Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public function getDirectoryWrite($directoryCode, $driverCode = DriverPool::REMO
$uri = $this->getUri($directoryCode) ?: '';
$this->writeInstances[$code] = $this->writeFactory->create(
$this->driverPool->getDriver()->getAbsolutePath('', $uri),
$driverCode,
null,
$directoryCode
$driverCode
);
}

Expand Down
78 changes: 78 additions & 0 deletions Plugin/MediaStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\RemoteStorage\Plugin;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\RuntimeException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\MediaStorage\Model\File\Storage\Synchronization;
use Magento\RemoteStorage\Driver\DriverPool as RemoteDriverPool;
use Magento\Framework\Filesystem\DriverPool as LocalDriverPool;
use Magento\RemoteStorage\Model\Config;
use Magento\RemoteStorage\Filesystem;

/**
* Modifies the base URL.
*/
class MediaStorage
{
/**
* @var bool
*/
private $isEnabled;

/**
* @var WriteInterface
*/
private $remoteDirectory;

/**
* @var WriteInterface
*/
private $localDirectory;

/**
* @param Config $config
* @param Filesystem $filesystem
* @throws FileSystemException
* @throws RuntimeException
*/
public function __construct(Config $config, Filesystem $filesystem)
{
$this->isEnabled = $config->isEnabled();
$this->remoteDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB, RemoteDriverPool::REMOTE);
$this->localDirectory = $filesystem->getDirectoryWrite(DirectoryList::PUB, LocalDriverPool::FILE);
}

/**
* Download remote file
*
* @param Synchronization $subject
* @param string $relativeFileName
* @return null
* @throws FileSystemException
* @throws ValidatorException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeSynchronize(Synchronization $subject, string $relativeFileName): void
{
if ($this->isEnabled && $this->remoteDirectory->isExist($relativeFileName)) {
$file = $this->localDirectory->openFile($relativeFileName, 'w');
try {
$file->lock();
$file->write($this->remoteDirectory->readFile($relativeFileName));
$file->unlock();
$file->close();
} catch (FileSystemException $e) {
$file->close();
}
}
}
}
28 changes: 1 addition & 27 deletions Setup/ConfigOptionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface
private const CONFIG_PATH__REMOTE_STORAGE_DRIVER = RemoteDriverPool::PATH_DRIVER;
private const OPTION_REMOTE_STORAGE_PREFIX = 'remote-storage-prefix';
private const CONFIG_PATH__REMOTE_STORAGE_PREFIX = RemoteDriverPool::PATH_PREFIX;
private const OPTION_REMOTE_STORAGE_ENDPOINT = 'remote-storage-endpoint';
private const CONFIG_PATH__REMOTE_STORAGE_ENDPOINT = RemoteDriverPool::PATH_CONFIG . '/endpoint';
private const OPTION_REMOTE_STORAGE_BUCKET = 'remote-storage-bucket';
private const CONFIG_PATH__REMOTE_STORAGE_BUCKET = RemoteDriverPool::PATH_CONFIG . '/bucket';
private const OPTION_REMOTE_STORAGE_REGION = 'remote-storage-region';
Expand All @@ -37,8 +35,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface
private const CONFIG_PATH__REMOTE_STORAGE_ACCESS_KEY = RemoteDriverPool::PATH_CONFIG . '/credentials/key';
private const OPTION_REMOTE_STORAGE_SECRET_KEY = 'remote-storage-secret';
private const CONFIG_PATH__REMOTE_STORAGE_SECRET_KEY = RemoteDriverPool::PATH_CONFIG . '/credentials/secret';
private const OPTION_REMOTE_STORAGE_PATH_STYLE = 'remote-storage-path-style';
private const CONFIG_PATH__REMOTE_STORAGE_PATH_STYLE = RemoteDriverPool::PATH_CONFIG . '/path-style';

/**
* Map of option to config path relations.
Expand All @@ -47,12 +43,10 @@ class ConfigOptionsList implements ConfigOptionsListInterface
*/
private static $map = [
self::OPTION_REMOTE_STORAGE_PREFIX => self::CONFIG_PATH__REMOTE_STORAGE_PREFIX,
self::OPTION_REMOTE_STORAGE_ENDPOINT => self::CONFIG_PATH__REMOTE_STORAGE_ENDPOINT,
self::OPTION_REMOTE_STORAGE_BUCKET => self::CONFIG_PATH__REMOTE_STORAGE_BUCKET,
self::OPTION_REMOTE_STORAGE_REGION => self::CONFIG_PATH__REMOTE_STORAGE_REGION,
self::OPTION_REMOTE_STORAGE_ACCESS_KEY => self::CONFIG_PATH__REMOTE_STORAGE_ACCESS_KEY,
self::OPTION_REMOTE_STORAGE_SECRET_KEY => self::CONFIG_PATH__REMOTE_STORAGE_SECRET_KEY,
self::OPTION_REMOTE_STORAGE_PATH_STYLE => self::CONFIG_PATH__REMOTE_STORAGE_PATH_STYLE
self::OPTION_REMOTE_STORAGE_SECRET_KEY => self::CONFIG_PATH__REMOTE_STORAGE_SECRET_KEY
];

/**
Expand Down Expand Up @@ -95,12 +89,6 @@ public function getOptions(): array
'Remote storage prefix',
''
),
new TextConfigOption(
self::OPTION_REMOTE_STORAGE_ENDPOINT,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::CONFIG_PATH__REMOTE_STORAGE_ENDPOINT,
'Remote storage endpoint'
),
new TextConfigOption(
self::OPTION_REMOTE_STORAGE_BUCKET,
TextConfigOption::FRONTEND_WIZARD_TEXT,
Expand All @@ -126,13 +114,6 @@ public function getOptions(): array
self::CONFIG_PATH__REMOTE_STORAGE_SECRET_KEY,
'Remote storage secret key',
''
),
new TextConfigOption(
self::OPTION_REMOTE_STORAGE_PATH_STYLE,
TextConfigOption::FRONTEND_WIZARD_PASSWORD,
self::CONFIG_PATH__REMOTE_STORAGE_PATH_STYLE,
'Remote storage path style',
'0'
)
];
}
Expand Down Expand Up @@ -160,13 +141,6 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig)
*/
public function validate(array $options, DeploymentConfig $deploymentConfig): array
{
// deployment configuration existence determines readiness of object manager to resolve remote storage drivers
$isDeploymentConfigExists = (bool) $deploymentConfig->getConfigData();

if (!$isDeploymentConfigExists) {
return [];
}

$driver = $options[self::OPTION_REMOTE_STORAGE_DRIVER] ?? DriverPool::FILE;

if ($driver === DriverPool::FILE) {
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"name": "test-magenx/module-remote-storage",
"description": "N/A",
"require": {
"php": "~7.4.0||~8.0.0",
"magento/framework": "*"
},
"suggest": {
"magento/module-backend": "*",
"magento/module-sitemap": "*",
"magento/module-cms": "*",
"magento/module-downloadable": "*",
"magento/module-catalog": "*",
"magento/module-media-storage": "*",
"magento/module-import-export": "*",
"magento/module-catalog-import-export": "*",
"magento/module-downloadable-import-export": "*",
"predis/predis": "*"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"version": "100.4.1",
"require": {
"php": "~7.3.0||~7.4.0",
"magento/framework": "103.0.*"
},
"suggest": {
"magento/module-backend": "102.0.*",
"magento/module-sitemap": "100.4.*",
"magento/module-cms": "104.0.*",
"magento/module-downloadable": "100.4.*",
"magento/module-catalog": "104.0.*",
"magento/module-media-storage": "100.4.*",
"magento/module-import-export": "101.0.*",
"magento/module-catalog-import-export": "101.1.*",
"magento/module-downloadable-import-export": "100.4.*",
"predis/predis": "*"
},
"autoload": {
"files": [
"registration.php"
Expand Down
10 changes: 4 additions & 6 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<preference for="Magento\RemoteStorage\Driver\Adapter\CachedAdapterInterface" type="Magento\RemoteStorage\Driver\Adapter\CachedAdapter"/>
<preference for="Magento\RemoteStorage\Driver\Adapter\MetadataProviderInterface" type="Magento\RemoteStorage\Driver\Adapter\MetadataProvider"/>
<preference for="Magento\RemoteStorage\Driver\Adapter\MetadataProviderFactoryInterface" type="Magento\RemoteStorage\Driver\Adapter\MetadataProviderFactory"/>
<preference for="Magento\Framework\Filesystem\DriverPool" type="Magento\RemoteStorage\Driver\DriverPool"/>
<virtualType name="remoteWriteFactory" type="Magento\Framework\Filesystem\Directory\WriteFactory">
<arguments>
<argument name="driverPool" xsi:type="object">Magento\RemoteStorage\Driver\DriverPool</argument>
Expand All @@ -23,9 +22,8 @@
</virtualType>
<type name="Magento\RemoteStorage\Filesystem">
<arguments>
<argument name="writeFactory" xsi:type="object">
Magento\RemoteStorage\Model\Filesystem\Directory\WriteFactory
</argument>
<argument name="writeFactory" xsi:type="object">remoteWriteFactory</argument>
<argument name="readFactory" xsi:type="object">remoteReadFactory</argument>
</arguments>
</type>
<virtualType name="customRemoteFilesystem" type="Magento\RemoteStorage\Filesystem">
Expand Down Expand Up @@ -77,8 +75,8 @@
<argument name="filesystem" xsi:type="object">fullRemoteFilesystem</argument>
</arguments>
</type>
<type name="Magento\MediaStorage\Model\File\Storage\SynchronizationFactory">
<plugin name="remoteMediaStorageSynchronizationFactory" type="Magento\RemoteStorage\Plugin\File\Storage\SynchronizationFactory" />
<type name="Magento\MediaStorage\Model\File\Storage\Synchronization">
<plugin name="remoteMedia" type="Magento\RemoteStorage\Plugin\MediaStorage" />
</type>
<type name="Magento\Framework\Data\Collection\Filesystem">
<arguments>
Expand Down

0 comments on commit 4bf1800

Please sign in to comment.