From e58190a9b33e54f254df032ce315451516d705b3 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 28 Nov 2017 09:45:40 +1300 Subject: [PATCH] API Rename IgnoreCodes configuration property to ignore_codes --- README.md | 28 +++++++++++++++++----------- src/Model/BrokenExternalLink.php | 9 ++++----- src/Tasks/CheckExternalLinksTask.php | 28 +++++++++++++++++++--------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 5e2f450..8575c73 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/Model/BrokenExternalLink.php b/src/Model/BrokenExternalLink.php index 0aa2037..366057a 100644 --- a/src/Model/BrokenExternalLink.php +++ b/src/Model/BrokenExternalLink.php @@ -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 @@ public function canEdit($member = false) 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); } diff --git a/src/Tasks/CheckExternalLinksTask.php b/src/Tasks/CheckExternalLinksTask.php index 84a8551..d83d5fe 100644 --- a/src/Tasks/CheckExternalLinksTask.php +++ b/src/Tasks/CheckExternalLinksTask.php @@ -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 @@ protected function isCodeBroken($httpCode) } // 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; }