From bb302882524d654bd8621d97723ef09930372b14 Mon Sep 17 00:00:00 2001 From: Kirk Mayo Date: Mon, 28 Jul 2014 11:23:33 +1200 Subject: [PATCH] NEW: Adding report link to setup new queued job --- _config/routes.yml | 7 ++ code/controllers/CMSExternalLinks.php | 20 +++++ code/jobs/CheckExternalLinksJob.php | 4 +- code/reports/BrokenExternalLinksReport.php | 87 ++++++++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 _config/routes.yml create mode 100644 code/controllers/CMSExternalLinks.php create mode 100644 code/reports/BrokenExternalLinksReport.php diff --git a/_config/routes.yml b/_config/routes.yml new file mode 100644 index 0000000..2284d3a --- /dev/null +++ b/_config/routes.yml @@ -0,0 +1,7 @@ +--- +Name: externallink +After: framework/routes +--- +Director: + rules: + 'admin/externallinks//$Action': 'CMSExternalLinks_Controller' diff --git a/code/controllers/CMSExternalLinks.php b/code/controllers/CMSExternalLinks.php new file mode 100644 index 0000000..e6769d1 --- /dev/null +++ b/code/controllers/CMSExternalLinks.php @@ -0,0 +1,20 @@ +queueJob($externalLinks); + + // redirect to the jobs page + $admin = QueuedJobsAdmin::create(); + $this->Redirect($admin->Link()); + } +} diff --git a/code/jobs/CheckExternalLinksJob.php b/code/jobs/CheckExternalLinksJob.php index 381df5b..ba569ca 100644 --- a/code/jobs/CheckExternalLinksJob.php +++ b/code/jobs/CheckExternalLinksJob.php @@ -1,5 +1,7 @@ '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 = ''; + $runReportButton = new LiteralField( + 'runReport', + sprintf( + $button, + 'admin/externallinks/createQueuedReport', + _t('ExternalBrokenLinksReport.RUNREPORT', 'Create new report') + ) + ); + $fields->push($runReportButton); + $reportResultSpan = ''; + $reportResult = new LiteralField('ResultTitle', $reportResultSpan); + $fields->push($reportResult); + } + return $fields; + } +}