mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
NEW: Adding report link to setup new queued job
This commit is contained in:
parent
a3c693189b
commit
bb30288252
7
_config/routes.yml
Normal file
7
_config/routes.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
Name: externallink
|
||||
After: framework/routes
|
||||
---
|
||||
Director:
|
||||
rules:
|
||||
'admin/externallinks//$Action': 'CMSExternalLinks_Controller'
|
20
code/controllers/CMSExternalLinks.php
Normal file
20
code/controllers/CMSExternalLinks.php
Normal file
@ -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());
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
if(!class_exists('AbstractQueuedJob')) return;
|
||||
|
||||
/**
|
||||
* A Job for running a external link check for published pages
|
||||
*
|
||||
@ -13,7 +15,7 @@ class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob {
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return 'Checking external links';
|
||||
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links');
|
||||
}
|
||||
|
||||
public function getJobType() {
|
||||
|
87
code/reports/BrokenExternalLinksReport.php
Normal file
87
code/reports/BrokenExternalLinksReport.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user