Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add curlOptions to remote asset download #552

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/get-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ return [
- `queueTtr` - Set the 'time to reserve' time in seconds, to prevent the job being cancelled after 300 seconds (default).
- `queueMaxRetry` - Set the maxiumum 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.
- `curlOptions` - Any additionl CURLOPT_XXX options when `assetDownloadCurl` is set to `true`
- `feedOptions` - Provide an array of any of the above options or [Feed Settings](../feature-tour/feed-overview.md) to set specifically for certain feeds. Use the Feed ID as the key for the array.

#### Example `requestOptions`

See [Guzzle Options](http://docs.guzzlephp.org/en/stable/request-options.html) for the full range:

```php
Expand All @@ -69,6 +71,18 @@ See [Guzzle Options](http://docs.guzzlephp.org/en/stable/request-options.html) f

```

#### Example `curlOptions`

See [curl_setopt](https://www.php.net/manual/en/function.curl-setopt.php) for the full range:

```php
'assetDownloadCurl' => true,
'curlOptions' => [
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13'
],

```

## Control Panel

You can also manage configuration settings through the Control Panel by visiting Settings → Feed Me.
10 changes: 8 additions & 2 deletions src/helpers/AssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ public static function downloadFile($srcName, $dstName, $chunkSize = 1, $returnb
$ch = curl_init($srcName);
$fp = fopen($dstName, 'wb');

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$defaultOptions = [
CURLOPT_FILE => $fp,
CURLOPT_FOLLOWLOCATION => 1
];

// merge default options with config setting, config overrides default.
$options = Plugin::$plugin->getSettings()->curlOptions + $defaultOptions;
curl_setopt_array($ch, $options);

curl_exec($ch);
curl_close($ch);
Expand Down
1 change: 1 addition & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class Settings extends Model
public $queueTtr = 300;
public $queueMaxRetry = 5;
public $assetDownloadCurl = false;
public $curlOptions = [];

}