Skip to content

Commit a0c0adc

Browse files
Initial changes (#1)
* Changed namespace, and fixed errors * typos * Missing * Altered Readme * Update README.md * Update README.md * Update README.md * changed config path
1 parent 079cdcb commit a0c0adc

File tree

16 files changed

+89
-234
lines changed

16 files changed

+89
-234
lines changed

.travis.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

Helper/Data.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
<?php
2-
/**
3-
* Phoenix_MediaStorageSync for Magento 2
4-
*
5-
*
6-
* @category Phoenix
7-
* @package Phoenix_MediaStorageSync
8-
* @license http://opensource.org/licenses/MIT MIT
9-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
10-
*/
112

12-
namespace Phoenix\MediaStorageSync\Helper;
3+
namespace Salecto\MediaStorageSync\Helper;
134

145
use Magento\Framework\App\Helper\AbstractHelper;
156
use Magento\Framework\App\Helper\Context;

Model/Config.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
<?php
2-
/**
3-
* Phoenix_MediaStorageSync for Magento 2
4-
*
5-
*
6-
* @category Phoenix
7-
* @package Phoenix_MediaStorageSync
8-
* @license http://opensource.org/licenses/MIT MIT
9-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
10-
*/
11-
12-
namespace Phoenix\MediaStorageSync\Model;
132

3+
namespace Salecto\MediaStorageSync\Model;
144

155
use Magento\Framework\App\Config\ScopeConfigInterface;
166

@@ -103,6 +93,6 @@ public function getDownloadLimit()
10393
*/
10494
protected function getXmlPathPrefix()
10595
{
106-
return 'phoenix_mediastoragesync/general/';
96+
return 'media_storage_sync/general/';
10797
}
10898
}

Model/Sync.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<?php
2-
/**
3-
* Phoenix_MediaStorageSync for Magento 2
4-
*
5-
*
6-
* @category Phoenix
7-
* @package Phoenix_MediaStorageSync
8-
* @license http://opensource.org/licenses/MIT MIT
9-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
10-
*/
11-
12-
namespace Phoenix\MediaStorageSync\Model;
13-
14-
use Phoenix\MediaStorageSync\Helper\Data as Helper;
2+
3+
namespace Salecto\MediaStorageSync\Model;
4+
5+
use Salecto\MediaStorageSync\Helper\Data as Helper;
156
use Magento\Framework\HTTP\ClientFactory;
167
use Magento\Framework\HTTP\ClientInterface;
178
use Magento\Framework\Filesystem\Io\File;
@@ -101,9 +92,14 @@ public function sync($src, $target)
10192
*/
10293
protected function saveFileFromRemoteServer($src, $target)
10394
{
95+
if (strstr($target, 'media/') !== false) {
96+
$src = preg_replace('/^media\//', '', $src);
97+
}
98+
10499
$fileSaved = false;
105100
$fileName = basename($src);
106101
$fileDirectory = $target;
102+
107103
if ($fileName != $src) {
108104
$fileDirectory .= dirname($src);
109105
}
@@ -154,7 +150,7 @@ public function getHttpClient()
154150
$client = $this->httpClientFactory->create();
155151

156152
$client->setTimeout(20);
157-
$client->addHeader('User-Agent', 'Phoenix MediaStorageSync');
153+
$client->addHeader('User-Agent', 'Salecto MediaStorageSync');
158154
$client->addHeader('Content-Transfer-Encoding', 'binary');
159155

160156
$user = $this->config->getHttpClientUser();

Observer/Product/CollectionObserver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Phoenix\MediaStorageSync\Observer\Product;
3+
namespace Salecto\MediaStorageSync\Observer\Product;
44

55
use Magento\Framework\Event\ObserverInterface;
66
use Magento\Framework\Event\Observer;
77
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
8-
use Phoenix\MediaStorageSync\Model\Sync;
9-
use Phoenix\MediaStorageSync\Model\Config;
10-
use Phoenix\MediaStorageSync\Helper\Data as Helper;
8+
use Salecto\MediaStorageSync\Model\Sync;
9+
use Salecto\MediaStorageSync\Model\Config;
10+
use Salecto\MediaStorageSync\Helper\Data as Helper;
1111

1212
class CollectionObserver implements ObserverInterface
1313
{
@@ -54,7 +54,7 @@ public function execute(Observer $observer)
5454

5555
if ($fileIsNotAvailable) {
5656
$this->sync->sync(
57-
$this->helper->getCatalogMediaConfigPath() . $mediaGalleryImage->getData('file'),
57+
$this->helper->getCatalogMediaConfigPath() . "/" . $mediaGalleryImage->getData('file'),
5858
$this->helper->getMediaBaseDir()
5959
);
6060
}

Observer/ProductObserver.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?php
2-
/**
3-
* Phoenix_MediaStorageSync for Magento 2
4-
*
5-
*
6-
* @category Phoenix
7-
* @package Phoenix_MediaStorageSync
8-
* @license http://opensource.org/licenses/MIT MIT
9-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
10-
*/
112

12-
namespace Phoenix\MediaStorageSync\Observer;
3+
namespace Salecto\MediaStorageSync\Observer;
134

145
use Magento\Framework\Event\ObserverInterface;
156
use Magento\Framework\Event\Observer;
167
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
17-
use Phoenix\MediaStorageSync\Model\Sync;
18-
use Phoenix\MediaStorageSync\Model\Config;
19-
use Phoenix\MediaStorageSync\Helper\Data as Helper;
8+
use Salecto\MediaStorageSync\Model\Sync;
9+
use Salecto\MediaStorageSync\Model\Config;
10+
use Salecto\MediaStorageSync\Helper\Data as Helper;
2011

2112
class ProductObserver implements ObserverInterface
2213
{
@@ -63,7 +54,7 @@ public function execute(Observer $observer)
6354

6455
if ($fileIsNotAvailable) {
6556
$this->sync->sync(
66-
$this->helper->getCatalogMediaConfigPath() . $mediaGalleryImage->getData('file'),
57+
$this->helper->getCatalogMediaConfigPath() . "/" . $mediaGalleryImage->getData('file'),
6758
$this->helper->getMediaBaseDir()
6859
);
6960
}

Plugin/Synchronization.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
<?php
2-
/**
3-
* Phoenix_MediaStorageSync for Magento 2
4-
*
5-
*
6-
* @category Phoenix
7-
* @package Phoenix_MediaStorageSync
8-
* @license http://opensource.org/licenses/MIT MIT
9-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
10-
*/
112

12-
namespace Phoenix\MediaStorageSync\Plugin;
3+
namespace Salecto\MediaStorageSync\Plugin;
134

145
use Magento\MediaStorage\Model\File\Storage\Database as StorageDatabase;
15-
use Phoenix\MediaStorageSync\Model\Config;
16-
use Phoenix\MediaStorageSync\Model\Sync;
17-
use Phoenix\MediaStorageSync\Helper\Data as Helper;
6+
use Salecto\MediaStorageSync\Model\Config;
7+
use Salecto\MediaStorageSync\Model\Sync;
8+
use Salecto\MediaStorageSync\Helper\Data as Helper;
189

1910

2011
class Synchronization

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
## Phoenix Media Storage Sync
2-
The module retrieves files in /media from an origin server.
1+
# Media Storage Sync
2+
*This project is a fork of [this repo](https://github.com/PHOENIX-MEDIA/magento2-mediastoragesync). Since it was no longer maintained, and contained critical bugs, we haved decided to continue maintaining it, under a new name. Kudos to [Phoenix Media](https://www.phoenix-media.eu/de/) for their work.*
3+
---
4+
The module retrieves files in /media from an origin server/url. Useful if you have a local development environment for your shop, and don't want to download the whole media folder along with the shop.
35

4-
### What it does
6+
This module will try to download the images from the provided url, as they are required.
7+
8+
## What it does
59

610
Imagine you have a fresh local development environment with the Magento code checked out.
711
You retrieved the database but you don't have any of the media assets and your store frontend
@@ -14,7 +18,7 @@ products and CMS blocks/pages from a configurable origin server similar to a CDN
1418
you load an entity from the database. This means you can forget about the media folder and
1519
just browse the frontend as images are downloaded and saved transparently.
1620

17-
### How it works
21+
## How it works
1822

1923
In the module's configuration you can configure a base URL, the domain where your production/staging
2024
Magento instance is located from which to picked the database. In the database the relative
@@ -23,34 +27,30 @@ simply checks if their images are already in media/catalog. If not it uses the b
2327
appends the relative image path from the database and downloads the files from origin server.
2428
This slows down page generation the first time you access a page but improves pretty quickly.
2529

26-
For other assets in the media folder we make use of another mechanism: Maybe you recognized
27-
Magento is shipped with a get.php file in the Magento root. It was intended to retrieve image
28-
data from a database, save it on the host's filesystem and then deliver it. Well, our assets
29-
are located at a different web server but beside the retrieval of the asset data the rest is
30-
pretty similar.
31-
The get.php is called via a mod_rewrite rule in the media/.htaccess or equivalent rules in
32-
your nginx configuration. The process is triggered every time a file in /media is not found
33-
so it is only triggered the first time. The MediaStorageSync module downloads the file, saves
34-
it and the get.php delivers the file. On the second load the web service can directly deliver
35-
the static asset.
30+
## Settings
3631

37-
### How to use
32+
- `Enable` - Self explanatory
33+
- `URL` - The url full url of the shop you want to download medias from (e.g. https://yoursite.com/)
34+
- `HTTP Client User`- Username, in case of need for authorization
35+
- `HTTP CLient Password`- Password, in case of need for authorization
36+
- `Download Limit Per Request`- Limit the amount of downloads per request
3837

39-
1. Install the module via Composer:
40-
```
41-
composer require phoenix-media/magento2-mediastoragesync
42-
```
43-
2. Enable it
44-
``` bin/magento module:enable Phoenix_MediaStorageSync ```
45-
3. Install the module and rebuild the DI cache
46-
``` bin/magento setup:upgrade ```
38+
## Developer informations
4739

48-
### How to configure
40+
### Install module
4941

50-
Find the modules configuration in the PHOENIX MEDIA section of your Magento configuration.
42+
1. Install the module via Composer:
43+
```
44+
composer require salecto2/magento2-mediastoragesync
45+
```
46+
2. Enable it
5147
52-
Enable: Enable or disable the functionality
48+
```
49+
php bin/magento module:enable Salecto_MediaStorageSync
50+
```
5351
54-
URL: Configure the source URL where to retrieve the images (e.g. "https://magento.com/")
52+
3. Install the module and rebuild the DI cache
5553
56-
optionally configure credentials for BasicAuth.
54+
```
55+
php bin/magento setup:upgrade
56+
```

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"name": "phoenix-media/magento2-mediastoragesync",
3-
"description": "The module retrieves files in /media from origin server.",
2+
"name": "salecto2/magento2-mediastoragesync",
3+
"description": "The module retrieves media files from origin server.",
44
"require": {
55
"php": "^7.0",
66
"magento/module-media-storage": "*"
77
},
88
"type": "magento2-module",
9-
"version": "1.2.2",
9+
"version": "1.0.0",
1010
"license": "MIT",
1111
"autoload": {
1212
"files": [
1313
"registration.php"
1414
],
1515
"psr-4": {
16-
"Phoenix\\MediaStorageSync\\": ""
16+
"Salecto\\MediaStorageSync\\": ""
1717
}
1818
}
1919
}

etc/acl.xml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
<?xml version="1.0"?>
2-
<!--
3-
/**
4-
* Phoenix_MediaStorageSync for Magento 2
5-
*
6-
*
7-
* @category Phoenix
8-
* @package Phoenix_MediaStorageSync
9-
* @license http://opensource.org/licenses/MIT MIT
10-
* @copyright Copyright (c) 2018 PHOENIX MEDIA GmbH (http://www.phoenix-media.eu)
11-
*/
12-
-->
2+
133
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
144
<acl>
155
<resources>
166
<resource id="Magento_Backend::admin">
177
<resource id="Magento_Backend::stores">
188
<resource id="Magento_Backend::stores_settings">
199
<resource id="Magento_Config::config">
20-
<resource id="Phoenix_MediaStorageSync::config" title="Media Storage Sync Section" sortOrder="75" />
10+
<resource id="Salecto_MediaStorageSync::config" title="Media Storage Sync Section" sortOrder="75" />
2111
</resource>
2212
</resource>
2313
</resource>

0 commit comments

Comments
 (0)