diff --git a/code/jobs/CheckExternalLinksJob.php b/code/jobs/CheckExternalLinksJob.php index 030f1ea..56dd1e3 100644 --- a/code/jobs/CheckExternalLinksJob.php +++ b/code/jobs/CheckExternalLinksJob.php @@ -25,7 +25,14 @@ public function getSignature() { */ public function process() { $task = new CheckExternalLinks(); - $task->run(); + $pages = Versioned::get_by_stage('SiteTree', 'Live'); + // set the limit so each page is done individually + $task->limit = 1; + $this->totalSteps = $pages->count(); + foreach ($pages as $page) { + $this->currentStep++; + $task->run(); + } $this->isComplete = true; return; } diff --git a/code/tasks/CheckExternalLinks.php b/code/tasks/CheckExternalLinks.php index 960987f..f3df02c 100644 --- a/code/tasks/CheckExternalLinks.php +++ b/code/tasks/CheckExternalLinks.php @@ -1,7 +1,8 @@ filter(array( 'TrackID' => $track->ID, 'Processed' => 0 - ))->limit(10)->column('PageID'); + ))->limit($this->limit)->column('PageID'); $pages = Versioned::get_by_stage('SiteTree', 'Live') ->filter('ID', $batch) - ->limit(10); + ->limit($this->limit); $this->updateJobInfo('Fetching pages to check'); if ($track->CompletedPages == $track->TotalPages) { $track->Status = 'Completed'; @@ -50,7 +51,7 @@ function run($request) { $batch = BrokenExternalPageTrack::get() ->filter(array( 'TrackID' => $track->ID - ))->limit(10)->column('PageID'); + ))->limit($this->limit)->column('PageID'); $pages = Versioned::get_by_stage('SiteTree', 'Live') ->filter('ID', $batch); @@ -159,8 +160,13 @@ function run($request) { $row->delete(); } } else { - $this->updateJobInfo("Running next batch {$track->CompletedPages}/{$track->TotalPages}"); - $this->run($request); + // if running via the queued job module return to the queued job after each iteration + if ($this->limit == 1) { + return; + } else { + $this->updateJobInfo("Running next batch {$track->CompletedPages}/{$track->TotalPages}"); + $this->run($request); + } } // run this again if queued jobs exists and is a valid int diff --git a/javascript/BrokenExternalLinksReport.js b/javascript/BrokenExternalLinksReport.js index 5dd7046..54174f4 100644 --- a/javascript/BrokenExternalLinksReport.js +++ b/javascript/BrokenExternalLinksReport.js @@ -2,7 +2,6 @@ $('#externalLinksReport').entwine({ onclick: function() { $(this).start(); - $(this).poll(); }, onmatch: function() { $(this).poll(); @@ -12,11 +11,13 @@ $('#ReportHolder').empty(); $('#ReportHolder').text('Running report 0%'); $('#ReportHolder').append(''); + $('#externalLinksReport').hide(); $.ajax({url: "admin/externallinks/start", async: true, timeout: 3000 }); $(this).poll(); }, poll: function() { // poll the current job and update the front end status + $('#externalLinksReport').hide(); $.ajax({ url: "admin/externallinks/getJobStatus", async: true, @@ -30,6 +31,7 @@ var jobStatus = obj.Status ? obj.Status : 'Running'; if (jobStatus == 'Completed') { $('#ReportHolder').text('Report Finished ' + completed + '/' + total); + $('#externalLinksReport').show(); } else { setTimeout(function() { $('#externalLinksReport').poll(); }, 1000); }