mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
NEW: Adding whitelisted codes via yml
This commit is contained in:
parent
093322fcd3
commit
564514b015
18
README.md
18
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
|
||||
Add the following yml config to config.yml in mysite/_config have the the task run once every day (86400 seconds)
|
||||
|
||||
```
|
||||
CheckExternalLinks:
|
||||
Delay: 86400
|
||||
```
|
||||
CheckExternalLinks:
|
||||
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);
|
||||
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||
curl_close($handle);
|
||||
if (($httpCode < 200 || $httpCode > 302)
|
||||
|| ($href == '' || $href[0] == '/'))
|
||||
{
|
||||
// do we have any whitelisted codes
|
||||
$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->PageID = $page->ID;
|
||||
$brokenLink->Link = $href;
|
||||
|
Loading…
Reference in New Issue
Block a user