mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-06-16 09:41:37 +02:00
NEW: Adding whitelisted codes via yml
This commit is contained in:
parent
093322fcd3
commit
564514b015
16
README.md
16
README.md
|
@ -41,7 +41,17 @@ broken links.
|
||||||
If you have the queuedjobs module installed you can set the task to be run every so ofter
|
If you have the queuedjobs module installed you can set the task to be run every so ofter
|
||||||
Add the following yml config to config.yml in mysite/_config have the the task run once every day (86400 seconds)
|
Add the following yml config to config.yml in mysite/_config have the the task run once every day (86400 seconds)
|
||||||
|
|
||||||
```
|
CheckExternalLinks:
|
||||||
CheckExternalLinks:
|
|
||||||
Delay: 86400
|
Delay: 86400
|
||||||
```
|
|
||||||
|
## Whitelisting codes ##
|
||||||
|
|
||||||
|
If you want to ignore or whitelist certain http codes this can be setup via IgnoreCodes in the config.yml
|
||||||
|
file in mysite/_config
|
||||||
|
|
||||||
|
CheckExternalLinks:
|
||||||
|
Delay: 60
|
||||||
|
IgnoreCodes:
|
||||||
|
- 401
|
||||||
|
- 403
|
||||||
|
- 501
|
||||||
|
|
|
@ -61,9 +61,14 @@ class CheckExternalLinks extends BuildTask {
|
||||||
$response = curl_exec($handle);
|
$response = curl_exec($handle);
|
||||||
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||||
curl_close($handle);
|
curl_close($handle);
|
||||||
if (($httpCode < 200 || $httpCode > 302)
|
// do we have any whitelisted codes
|
||||||
|| ($href == '' || $href[0] == '/'))
|
$ignoreCodes = Config::inst()->get('CheckExternalLinks', 'IgnoreCodes');
|
||||||
{
|
// if the code is whitelisted set it to 200
|
||||||
|
$httpCode = (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) ?
|
||||||
|
200 : $httpCode;
|
||||||
|
|
||||||
|
// ignore empty hrefs and internal links
|
||||||
|
if (($httpCode < 200 || $httpCode > 302) || ($href == '' || $href[0] == '/')) {
|
||||||
$brokenLink = new BrokenExternalLink();
|
$brokenLink = new BrokenExternalLink();
|
||||||
$brokenLink->PageID = $page->ID;
|
$brokenLink->PageID = $page->ID;
|
||||||
$brokenLink->Link = $href;
|
$brokenLink->Link = $href;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user