NEW: Adding whitelisted codes via yml

This commit is contained in:
Kirk Mayo 2014-07-30 15:29:24 +12:00
parent 093322fcd3
commit 564514b015
2 changed files with 22 additions and 7 deletions

View File

@ -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

View File

@ -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;