mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
fc0f7640dc
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105846 467b73ca-7a2a-4603-9d3b-597d59a354a9
109 lines
3.5 KiB
PHP
109 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Content side-report listing pages with broken links
|
|
* @package cms
|
|
* @subpackage content
|
|
*/
|
|
|
|
class BrokenLinksReport extends SS_Report {
|
|
function title() {
|
|
return _t('BrokenLinksReport.BROKENLINKS',"Broken links report");
|
|
}
|
|
function sourceRecords($params, $sort, $limit) {
|
|
$join = '';
|
|
if($sort) {
|
|
$parts = explode(' ', $sort);
|
|
$field = $parts[0];
|
|
$direction = $parts[1];
|
|
|
|
if($field == 'AbsoluteLink') {
|
|
$sort = 'URLSegment ' . $direction;
|
|
} elseif($field == 'Subsite.Title') {
|
|
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
|
} elseif($field == 'BrokenReason') {
|
|
$sort = "HasBrokenLink ASC, HasBrokenFile ASC";
|
|
}
|
|
}
|
|
|
|
if (!isset($_REQUEST['CheckSite']) || $params['CheckSite'] == 'Published') $ret = Versioned::get_by_stage('SiteTree', 'Live', "(HasBrokenLink = 1 OR HasBrokenFile = 1)", $sort, $join, $limit);
|
|
else $ret = DataObject::get('SiteTree', "(HasBrokenFile = 1 OR HasBrokenLink = 1)", $sort, $join, $limit);
|
|
|
|
$returnSet = new DataObjectSet();
|
|
if ($ret) foreach($ret as $record) {
|
|
$reason = false;
|
|
$isRedirectorPage = in_array($record->ClassName, ClassInfo::subclassesFor('RedirectorPage'));
|
|
$isVirtualPage = in_array($record->ClassName, ClassInfo::subclassesFor('VirtualPage'));
|
|
|
|
if ($isVirtualPage) {
|
|
if ($record->HasBrokenLink) {
|
|
$reason = "virtual page pointing to non-existent page";
|
|
$reasonCodes = array("VPBROKENLINK");
|
|
}
|
|
} else if ($isRedirectorPage) {
|
|
if ($record->HasBrokenLink) {
|
|
$reason = "redirector page pointing to non-existent page";
|
|
$reasonCodes = array("RPBROKENLINK");
|
|
}
|
|
} else {
|
|
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
|
$reason = "has broken link and file";
|
|
$reasonCodes = array("BROKENFILE", "BROKENLINK");
|
|
} else if ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
|
$reason = "has broken link";
|
|
$reasonCodes = array("BROKENLINK");
|
|
} else if (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
|
$reason = "has broken file";
|
|
$reasonCodes = array("BROKENFILE");
|
|
}
|
|
}
|
|
|
|
if ($reason) {
|
|
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) continue;
|
|
$record->BrokenReason = $reason;
|
|
$returnSet->push($record);
|
|
}
|
|
}
|
|
|
|
//if ($sort) $returnSet->sort($sort);
|
|
|
|
return $returnSet;
|
|
}
|
|
function columns() {
|
|
$fields = array(
|
|
"Title" => array(
|
|
"title" => "Page name",
|
|
'formatting' => '<a href=\"admin/show/$ID\" title=\"Edit page\">$value</a>'
|
|
),
|
|
"LastEdited" => array(
|
|
"title" => "Date ".(isset($_REQUEST['CheckSite']) && ($_REQUEST['CheckSite'] == 'Draft')?'last modified':'published'),
|
|
'casting' => 'SSDatetime->Full'
|
|
),
|
|
"BrokenReason" => array(
|
|
"title" => "Problem type"
|
|
),
|
|
'AbsoluteLink' => array(
|
|
'title' => 'URL',
|
|
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a href=\"$value?stage=Stage\">(draft)</a>'
|
|
)
|
|
);
|
|
|
|
return $fields;
|
|
}
|
|
function parameterFields() {
|
|
return new FieldSet(
|
|
new DropdownField('CheckSite', 'Check site', array(
|
|
'Published' => 'Published Site',
|
|
'Draft' => 'Draft Site'
|
|
)),
|
|
new DropdownField('Reason', 'Problem to check', array(
|
|
'' => 'Any',
|
|
'BROKENFILE' => 'Broken file',
|
|
'BROKENLINK' => 'Broken link',
|
|
'VPBROKENLINK' => 'Virtual page pointing to invalid source',
|
|
'RPBROKENLINK' => 'Redirector page pointing to invalid destination',
|
|
))
|
|
);
|
|
}
|
|
}
|