hryvinskyi/magento2-external-media-prefetcher
最新稳定版本:1.0.2
Composer 安装命令:
composer require hryvinskyi/magento2-external-media-prefetcher
包简介
N/A
README 文档
README
A Magento 2 module that automatically fetches missing media files from an external source.
Description
This module solves the common problem of missing media files in development or staging environments. When a media file is requested but not found locally, the module automatically attempts to download it from a configured external URL (such as your production site).
Requirements
- Magento 2.4.x
- PHP 7.4 or higher
Installation
Using Composer (recommended)
composer require hryvinskyi/magento2-external-media-prefetcher bin/magento module:enable Hryvinskyi_ExternalMediaPrefetcher bin/magento setup:upgrade
Manual Installation
- Create the following directory in your Magento installation:
app/code/Hryvinskyi/ExternalMediaPrefetcher - Copy the module files to this directory
- Enable the module and update the database:
bin/magento module:enable Hryvinskyi_ExternalMediaPrefetcher bin/magento setup:upgrade
Configuration
Modify your staging or local environment's app/etc/env.php file
and add this configuration under the system key:
'system' => [ 'default' => [ 'external_media_prefetcher' => [ 'general' => [ 'enabled' => 1, 'external_media_url' => 'https://www.example.com/media/' ] ] ] ]
- external_media_prefetcher/general/enabled: Set to
1to enable the module or0to disable it. - external_media_prefetcher/general/external_media_url: Set the base URL where media files should be fetched from (e.g.,
https://www.example.com/media/)
You can also set this configuration through cli commands:
bin/magento config:set external_media_prefetcher/general/enabled 1 --lock-env bin/magento config:set external_media_prefetcher/general/external_media_url https://www.example.com/media/ --lock-env
How It Works
When a media file is requested but not found locally:
- The module intercepts the request through a plugin on
Magento\MediaStorage\Model\File\Storage\Synchronization - It cleans the path if it contains cache information
- It constructs the external URL by combining the configured external media URL with the requested file path
- It creates the necessary directory structure locally
- It downloads the file from the external source and saves it to the local filesystem
Why it's Useful
- Development and Staging: Easily sync media files from production to development or staging environments.
- Missing Files: Automatically fetch missing files without manual intervention.
- Efficiency: Saves time and effort in managing media files across different environments.
License
Author
Volodymyr Hryvinskyi
Email: volodymyr@hryvinskyi.com
GitHub: https://github.com/hryvinskyi
统计信息
- 总下载量: 242
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-17