2010-02-04 05:52:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content side-report listing pages with broken links
|
|
|
|
* @package cms
|
|
|
|
* @subpackage content
|
|
|
|
*/
|
|
|
|
|
2010-02-04 06:11:02 +01:00
|
|
|
class BrokenLinksReport extends SS_Report {
|
2010-02-04 05:52:34 +01:00
|
|
|
function title() {
|
2010-02-04 05:53:22 +01:00
|
|
|
return _t('BrokenLinksReport.BROKENLINKS',"Broken links report");
|
2010-02-04 05:52:34 +01:00
|
|
|
}
|
2010-02-04 05:53:36 +01:00
|
|
|
function sourceRecords($params, $sort, $limit) {
|
2010-02-04 05:55:03 +01:00
|
|
|
$join = '';
|
2010-02-04 05:55:28 +01:00
|
|
|
$sortBrokenReason = false;
|
2010-02-04 05:55:03 +01:00
|
|
|
if($sort) {
|
|
|
|
$parts = explode(' ', $sort);
|
|
|
|
$field = $parts[0];
|
|
|
|
$direction = $parts[1];
|
|
|
|
|
|
|
|
if($field == 'AbsoluteLink') {
|
|
|
|
$sort = 'URLSegment ' . $direction;
|
2010-02-04 05:55:09 +01:00
|
|
|
} elseif($field == 'Subsite.Title') {
|
2010-02-04 05:55:03 +01:00
|
|
|
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
2010-02-04 05:55:09 +01:00
|
|
|
} elseif($field == 'BrokenReason') {
|
2010-02-04 05:55:28 +01:00
|
|
|
$sortBrokenReason = true;
|
|
|
|
$sort = '';
|
2010-02-04 05:55:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-02-04 05:52:34 +01:00
|
|
|
|
|
|
|
$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) {
|
2010-02-04 05:53:22 +01:00
|
|
|
$reason = "virtual page pointing to non-existent page";
|
2010-02-04 05:52:34 +01:00
|
|
|
$reasonCodes = array("VPBROKENLINK");
|
|
|
|
}
|
|
|
|
} else if ($isRedirectorPage) {
|
|
|
|
if ($record->HasBrokenLink) {
|
2010-02-04 05:53:22 +01:00
|
|
|
$reason = "redirector page pointing to non-existent page";
|
2010-02-04 05:52:34 +01:00
|
|
|
$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) {
|
2010-02-04 05:53:22 +01:00
|
|
|
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) continue;
|
2010-02-04 05:52:34 +01:00
|
|
|
$record->BrokenReason = $reason;
|
|
|
|
$returnSet->push($record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-04 05:55:28 +01:00
|
|
|
if($sortBrokenReason) $returnSet->sort('BrokenReason', $direction);
|
2010-02-04 05:53:42 +01:00
|
|
|
|
2010-02-04 05:52:34 +01:00
|
|
|
return $returnSet;
|
|
|
|
}
|
|
|
|
function columns() {
|
|
|
|
$fields = array(
|
|
|
|
"Title" => array(
|
2010-02-04 05:54:04 +01:00
|
|
|
"title" => "Page name",
|
2010-02-04 05:52:34 +01:00
|
|
|
'formatting' => '<a href=\"admin/show/$ID\" title=\"Edit page\">$value</a>'
|
|
|
|
),
|
2010-02-04 05:53:22 +01:00
|
|
|
"LastEdited" => array(
|
2010-02-04 05:53:28 +01:00
|
|
|
"title" => "Date ".(isset($_REQUEST['CheckSite']) && ($_REQUEST['CheckSite'] == 'Draft')?'last modified':'published'),
|
2010-02-04 05:53:22 +01:00
|
|
|
'casting' => 'SSDatetime->Full'
|
|
|
|
),
|
2010-02-04 05:52:34 +01:00
|
|
|
"BrokenReason" => array(
|
2010-02-04 05:53:22 +01:00
|
|
|
"title" => "Problem type"
|
2010-02-04 05:52:34 +01:00
|
|
|
),
|
|
|
|
'AbsoluteLink' => array(
|
2010-02-04 05:53:22 +01:00
|
|
|
'title' => 'URL',
|
2010-02-16 05:02:14 +01:00
|
|
|
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
|
2010-02-04 05:52:34 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
function parameterFields() {
|
|
|
|
return new FieldSet(
|
2010-02-04 05:53:28 +01:00
|
|
|
new DropdownField('CheckSite', 'Check site', array(
|
|
|
|
'Published' => 'Published Site',
|
|
|
|
'Draft' => 'Draft Site'
|
|
|
|
)),
|
2010-02-04 05:52:34 +01:00
|
|
|
new DropdownField('Reason', 'Problem to check', array(
|
|
|
|
'' => 'Any',
|
|
|
|
'BROKENFILE' => 'Broken file',
|
|
|
|
'BROKENLINK' => 'Broken link',
|
2010-02-04 05:55:33 +01:00
|
|
|
'VPBROKENLINK' => 'Virtual page pointing to non-existent page',
|
|
|
|
'RPBROKENLINK' => 'Redirector page pointing to non-existent page',
|
2010-02-04 05:52:34 +01:00
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|