mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
Merge pull request #1 from tractorcow/pulls/description
API Add description for response code to report
This commit is contained in:
commit
d9e1b998d7
@ -27,7 +27,7 @@ class BrokenExternalLink extends DataObject {
|
||||
|
||||
public static $summary_fields = array(
|
||||
'Page.Title' => 'Page',
|
||||
'HTTPCode' => 'HTTP Code',
|
||||
'HTTPCodeDescription' => 'HTTP Code',
|
||||
'Created' => 'Created'
|
||||
);
|
||||
|
||||
@ -35,15 +35,36 @@ class BrokenExternalLink extends DataObject {
|
||||
'HTTPCode' => array('title' => 'HTTP Code')
|
||||
);
|
||||
|
||||
function canEdit($member = false) {
|
||||
public function canEdit($member = false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function canView($member = false) {
|
||||
public function canView($member = false) {
|
||||
$member = $member ? $member : Member::currentUser();
|
||||
$codes = array('content-authors', 'administrators');
|
||||
return Permission::checkMember($member, $codes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a human readable description of a response code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHTTPCodeDescription() {
|
||||
$code = $this->HTTPCode;
|
||||
if(empty($code)) {
|
||||
// Assume that $code = 0 means there was no response
|
||||
$description = _t(__CLASS__.'.NOTAVAILABLE', 'Server Not Available');
|
||||
} elseif(
|
||||
($descriptions = Config::inst()->get('SS_HTTPResponse', 'status_codes'))
|
||||
&& isset($descriptions[$code])
|
||||
) {
|
||||
$description = $descriptions[$code];
|
||||
} else {
|
||||
$description = _t(__CLASS__.'.UNKNOWNRESPONSE', 'Unknown Response Code');
|
||||
}
|
||||
return sprintf("%d (%s)", $code, $description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ class BrokenExternalLinksReport extends SS_Report {
|
||||
);
|
||||
}
|
||||
),
|
||||
'HTTPCode' => 'HTTP Error Code',
|
||||
'HTTPCodeDescription' => 'HTTP Error Code',
|
||||
"Title" => array(
|
||||
"title" => 'Page link is on',
|
||||
'formatting' => function($value, $item) {
|
||||
|
@ -118,6 +118,16 @@ class ExternalLinksTest extends SapphireTest {
|
||||
);
|
||||
$actual = $links->map('Link', 'HTTPCode')->toArray();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
// Check response descriptions are correct
|
||||
i18n::set_locale('en_NZ');
|
||||
$expected = array(
|
||||
'http://www.broken.com' => '403 (Forbidden)',
|
||||
'http://www.broken.com/url/thing' => '404 (Not Found)',
|
||||
'http://www.nodomain.com' => '0 (Server Not Available)'
|
||||
);
|
||||
$actual = $links->map('Link', 'HTTPCodeDescription')->toArray();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user