Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR added broken links report (from r96139) (from r98187)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105834 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit 95346c7a36da580c9b6b565d2375f447c1757433 1 parent 3cfbc03
@chillu chillu authored
Showing with 91 additions and 1 deletion.
  1. +3 −1 _config.php
  2. +88 −0 code/reports/BrokenLinksReport.php
View
4 _config.php
@@ -53,4 +53,6 @@
// Register default side reports
SS_Report::register("SideReport", "SideReport_RecentlyEdited");
SS_Report::register("SideReport", "SideReport_EmptyPages");
-SS_Report::register("SideReport", "SideReport_ToDo");
+SS_Report::register("SideReport", "SideReport_ToDo");
+if (class_exists('Subsite')) SS_Report::register('ReportAdmin', 'SubsiteReportWrapper("BrokenLinksReport")',-20);
+else SS_Report::register('ReportAdmin', 'BrokenLinksReport',-20);
View
88 code/reports/BrokenLinksReport.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * Content side-report listing pages with broken links
+ * @package cms
+ * @subpackage content
+ */
+
+class BrokenLinksReport extends SS_Report {
+ function title() {
+ return _t('BrokenLinksReport.BROKENLINKS',"Pages with broken links");
+ }
+ function sourceRecords($params = null) {
+ // Get class names for page types that are not virtual pages or redirector pages
+ $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage'));
+ $classNames = "'".join("','", $classes)."'";
+
+ if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND (HasBrokenLink = 1 OR HasBrokenFile = 1)");
+ else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND (HasBrokenFile = 1 OR HasBrokenLink = 1)");
+
+ $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 = "redirector page pointing to non-existant page";
+ $reasonCodes = array("VPBROKENLINK");
+ }
+ } else if ($isRedirectorPage) {
+ if ($record->HasBrokenLink) {
+ $reason = "redirector page pointing to non-existant 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 ($params['Reason'] && !in_array($params['Reason'], $reasonCodes)) continue;
+ $record->BrokenReason = $reason;
+ $returnSet->push($record);
+ }
+ }
+
+ return $returnSet;
+ }
+ function columns() {
+ $fields = array(
+ "Title" => array(
+ "title" => "Title",
+ 'formatting' => '<a href=\"admin/show/$ID\" title=\"Edit page\">$value</a>'
+ ),
+ "BrokenReason" => array(
+ "title" => "Reason"
+ ),
+ 'AbsoluteLink' => array(
+ 'title' => 'Links',
+ 'formatting' => '$value " . ($AbsoluteLiveLink ? "<a href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a href=\"$value?stage=Stage\">(draft)</a>'
+ )
+ );
+
+ return $fields;
+ }
+ function parameterFields() {
+ return new FieldSet(
+ new CheckboxField('OnLive', 'Check live 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',
+ ))
+ );
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.