Skip to content

Commit

Permalink
Merge pull request #32 from creative-commoners/pulls/2.0/rename-confi…
Browse files Browse the repository at this point in the history
…g-props

API Rename IgnoreCodes configuration property to ignore_codes
  • Loading branch information
NightJar authored Nov 27, 2017
2 parents 6739163 + e58190a commit a119add
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`
9 changes: 4 additions & 5 deletions src/Model/BrokenExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
28 changes: 19 additions & 9 deletions src/Tasks/CheckExternalLinksTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a119add

Please sign in to comment.