Skip to content

Commit

Permalink
NEW: Adding report link to setup new queued job
Browse files Browse the repository at this point in the history
  • Loading branch information
kmayo-ss committed Jul 28, 2014
1 parent a3c6931 commit bb30288
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
7 changes: 7 additions & 0 deletions _config/routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: externallink
After: framework/routes
---
Director:
rules:
'admin/externallinks//$Action': 'CMSExternalLinks_Controller'
20 changes: 20 additions & 0 deletions code/controllers/CMSExternalLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class CMSExternalLinks_Controller extends Controller {

private static $allowed_actions = array('createQueuedReport');


public function createQueuedReport() {
if (!Permission::check('ADMIN')) return;

// setup external links job
$externalLinks = new CheckExternalLinksJob();
$job = singleton('QueuedJobService');
$jobID = $job->queueJob($externalLinks);

// redirect to the jobs page
$admin = QueuedJobsAdmin::create();
$this->Redirect($admin->Link());
}
}
4 changes: 3 additions & 1 deletion code/jobs/CheckExternalLinksJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

if(!class_exists('AbstractQueuedJob')) return;

/**
* A Job for running a external link check for published pages
*
Expand All @@ -13,7 +15,7 @@ public function __construct() {
}

public function getTitle() {
return 'Checking external links';
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links');
}

public function getJobType() {
Expand Down
87 changes: 87 additions & 0 deletions code/reports/BrokenExternalLinksReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* Content side-report listing pages with external broken links
* @package externallinks
* @subpackage content
*/

class BrokenExternalLinksReport extends SS_Report {

/**
* Columns in the report
*
* @var array
* @config
*/
private static $columns = array(
'Created' => 'Checked',
'Link' => 'External Link',
'HTTPCode' => 'HTTP Error Code',
'PageLink' => array(
'title' => 'Page link is on',
'link' => true
),
);

public function init() {
parent::init();
}

/**
* Returns the report title
*
* @return string
*/
public function title() {
return _t('ExternalBrokenLinksReport.EXTERNALBROKENLINKS',"External broken links report");
}

/**
* Returns the column names of the report
*
* @return array
*/
public function columns() {
return self::$columns;
}

/**
* Alias of columns(), to support the export to csv action
* in {@link GridFieldExportButton} generateExportFileData method.
* @return array
*/
public function getColumns() {
return $this->columns();
}

public function sourceRecords() {
$returnSet = new ArrayList();
$links = BrokenExternalLinks::get();
foreach ($links as $link) {
$link->PageLink = $link->Page()->Title;
$returnSet->push($link);
}
return $returnSet;
}

public function getCMSFields() {
$fields = parent::getCMSFields();
if (class_exists('AbstractQueuedJob')) {
$button = '<a href = "%s"><button class="externalLinksReport" type="button">%s</button></a>';
$runReportButton = new LiteralField(
'runReport',
sprintf(
$button,
'admin/externallinks/createQueuedReport',
_t('ExternalBrokenLinksReport.RUNREPORT', 'Create new report')
)
);
$fields->push($runReportButton);
$reportResultSpan = '<span id="ReportHolder"></span></ br><span id="ReportProgress"></span>';
$reportResult = new LiteralField('ResultTitle', $reportResultSpan);
$fields->push($reportResult);
}
return $fields;
}
}

0 comments on commit bb30288

Please sign in to comment.