From 0e514fb05f8146f5e449832b6bc351a3d3b1160d Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 19 Nov 2024 15:05:50 +0000 Subject: [PATCH 1/2] add option to download files for assets via guzzle --- src/helpers/AssetHelper.php | 17 ++++++++++++++++- src/models/Settings.php | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/helpers/AssetHelper.php b/src/helpers/AssetHelper.php index e05ea30d..2ab0ecb3 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; } From 89d0a96f260ee57fa5d8aa8e38ed73a03c90c84c Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Tue, 26 Nov 2024 16:52:32 -0800 Subject: [PATCH 2/2] Changelog and docs for https://github.com/craftcms/feed-me/pull/1549 --- CHANGELOG.md | 4 ++++ docs/get-started/configuration.md | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 116a6817..4de0c081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Feed Me +## 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)) + ## 5.8.2 - 2024-10-15 - When duplicating a feed, a new passkey is generated instead of using the passkey on the original feed. ([#1534](https://github.com/craftcms/feed-me/pull/1534)) 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`