diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ecb76d..6f625624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Added the `assetDownloadGuzzle` config setting which defaults to `false`. When it is set to `true`, Feed Me will use Guzzle to download assets instead curl directly. ([#1549](https://github.com/craftcms/feed-me/pull/1549)) - Imported Commerce Products now add a single Catalog Pricing job to the queue after an import, instead of one per Product. ([#1547](https://github.com/craftcms/feed-me/pull/1547)) ## 6.5.0 - 2024-10-15 diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 12a16b53..6b6e8792 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -53,6 +53,7 @@ return [ - `queueTtr` — Set the 'time to reserve' time in seconds, to prevent the job being cancelled after 300 seconds (default). - `queueMaxRetry` — Set the maximum amount of retries the queue job should have before failing. - `assetDownloadCurl` — Use curl to download assets from a remote source. Can be used when issues arise using the default implementation. +- `assetDownloadGuzzle` — Use Guzzle to download assets from a remote source. Can be used when issues arise using the default implementation. - `feedOptions` — Provide an array of any of the above options (or [feed settings](../feature-tour/feed-overview.md)) to set or override for specific feeds, keyed by their existing feed IDs. _Note that feed IDs may be different across environments!_ #### Example `requestOptions` diff --git a/src/helpers/AssetHelper.php b/src/helpers/AssetHelper.php index 50a673e6..dc66351d 100644 --- a/src/helpers/AssetHelper.php +++ b/src/helpers/AssetHelper.php @@ -53,10 +53,25 @@ public static function downloadFile($srcName, $dstName, int $chunkSize = 1, bool return fclose($fp); } + $fp = fopen($dstName, 'wb'); + + $assetDownloadGuzzle = Plugin::$plugin->service->getConfig('assetDownloadGuzzle', $feedId); + if ($assetDownloadGuzzle) { + $response = null; + $client = Plugin::$plugin->service->createGuzzleClient(); + try { + $response = $client->get($srcName, ['sink' => $fp]); + } catch (Throwable $e) { + } + + fclose($fp); + + return $response?->getStatusCode() === 200; + } + $newChunkSize = $chunkSize * (1024 * 1024); $bytesCount = 0; $handle = fopen($srcName, 'rb'); - $fp = fopen($dstName, 'wb'); if ($handle === false) { return false; diff --git a/src/models/Settings.php b/src/models/Settings.php index 0016d6ed..4955af91 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -102,4 +102,10 @@ class Settings extends Model * @var bool */ public bool $assetDownloadCurl = false; + + /** + * @var bool + * @since 5.9.0 + */ + public bool $assetDownloadGuzzle = false; }