Merge pull request #32 from creative-commoners/pulls/2.0/rename-config-props

API Rename IgnoreCodes configuration property to ignore_codes
This commit is contained in:
Dylan Wagstaff 2017-11-28 10:06:29 +13:00 committed by GitHub
commit a119add32e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 25 deletions

View File

@ -30,7 +30,7 @@ The external links module is a task and ModelAdmin to track and to report on bro
3. Run the following task *http://path.to.silverstripe/dev/tasks/CheckExternalLinks* to check for
broken external links
## Report ##
## Report
A new report is added called 'External Broken links report'. When viewing this report, a user may press
the "Create new report" button which will trigger an ajax request to initiate a report run.
@ -56,24 +56,30 @@ with the status. The user may leave this page and return to it later to view the
Any subsequent report may not be generated until a prior report has completed.
## Dev task ##
## Dev task
Run the following task *http://path.to.silverstripe/dev/tasks/CheckExternalLinks* to check your site for external
broken links.
## Queued job ##
## Queued job
If you have the queuedjobs module installed you can set the task to be run every so often.
## Whitelisting codes ##
## 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`
If you want to ignore or whitelist certain HTTP codes this can be setup via `ignore_codes` in the config.yml
file in `mysite/_config`:
```yml
SilverStripe\ExternalLinks\Tasks\CheckExternalLinksTask:
IgnoreCodes:
- 401
- 403
- 501
SilverStripe\ExternalLinks\Tasks\CheckExternalLinksTask:
ignore_codes:
- 401
- 403
- 501
```
## Upgrading from 1.x to 2.x
When upgrading from 1.x to 2.x (SilverStripe 3.x to 4.x) you will need to be aware of the following API changes:
* Configuration property `CheckExternalLinksTask.IgnoreCodes` renamed to `CheckExternalLinksTask.ignore_codes`

View File

@ -2,13 +2,12 @@
namespace SilverStripe\ExternalLinks\Model;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrack;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
/**
* Represents a single link checked for a single run that is broken
@ -56,7 +55,7 @@ class BrokenExternalLink extends DataObject
public function canView($member = false)
{
$member = $member ? $member : Member::currentUser();
$member = $member ? $member : Security::getCurrentUser();
$codes = array('content-authors', 'administrators');
return Permission::checkMember($member, $codes);
}

View File

@ -2,26 +2,36 @@
namespace SilverStripe\ExternalLinks\Tasks;
use DOMNode;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Debug;
use SilverStripe\ExternalLinks\Model\BrokenExternalLink;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrack;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Core\Config\Config;
use SilverStripe\ExternalLinks\Tasks\LinkChecker;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Dev\Debug;
use DOMNode;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ExternalLinks\Tasks\LinkChecker;
use SilverStripe\CMS\Model\SiteTree;
class CheckExternalLinksTask extends BuildTask
{
private static $dependencies = [
'LinkChecker' => '%$' . LinkChecker::class
];
private static $segment = 'CheckExternalLinksTask';
/**
* Define a list of HTTP response codes that should not be treated as "broken", where they usually
* might be.
*
* @config
* @var array
*/
private static $ignore_codes = [];
/**
* @var bool
*/
@ -135,7 +145,7 @@ class CheckExternalLinksTask extends BuildTask
}
// do we have any whitelisted codes
$ignoreCodes = $this->config()->get('IgnoreCodes');
$ignoreCodes = $this->config()->get('ignore_codes');
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) {
return false;
}