diff --git a/code/controllers/CMSExternalLinks.php b/code/controllers/CMSExternalLinks.php index 8e3ea1a..8579bdd 100644 --- a/code/controllers/CMSExternalLinks.php +++ b/code/controllers/CMSExternalLinks.php @@ -31,6 +31,21 @@ class CMSExternalLinks_Controller extends Controller { return; } if (class_exists('QueuedJobService')) { + $pages = Versioned::get_by_stage('SiteTree', 'Stage'); + $noPages = count($pages); + + $track = BrokenExternalPageTrackStatus::create(); + $track->TotalPages = $noPages; + $track->Status = 'Running'; + $track->write(); + + foreach ($pages as $page) { + $trackPage = BrokenExternalPageTrack::create(); + $trackPage->PageID = $page->ID; + $trackPage->TrackID = $track->ID; + $trackPage->write(); + } + $checkLinks = new CheckExternalLinksJob(); singleton('QueuedJobService') ->queueJob($checkLinks, date('Y-m-d H:i:s', time() + 1)); diff --git a/javascript/BrokenExternalLinksReport.js b/javascript/BrokenExternalLinksReport.js index d44f7b5..ff9acfb 100644 --- a/javascript/BrokenExternalLinksReport.js +++ b/javascript/BrokenExternalLinksReport.js @@ -6,7 +6,7 @@ onmatch: function() { // poll the current job and update the front end status $('#externalLinksReport').hide(); - $(this).poll(); + $(this).poll(0); }, start: function() { // initiate a new job @@ -15,9 +15,9 @@ $('#ReportHolder').append(''); $('#externalLinksReport').hide(); $.ajax({url: "admin/externallinks/start", async: true, timeout: 3000 }); - $(this).poll(); + $(this).poll(1); }, - poll: function() { + poll: function(start) { $.ajax({ url: "admin/externallinks/getJobStatus", async: true, @@ -32,11 +32,11 @@ var completed = obj.Completed ? obj.Completed : 0; var total = obj.Total ? obj.Total : 0; var jobStatus = obj.Status ? obj.Status : 'Running'; - if (jobStatus == 'Completed') { + if (jobStatus == 'Completed' && start == 0) { $('#ReportHolder').text('Report Finished ' + completed + '/' + total); $('#externalLinksReport').show(); } else { - setTimeout(function() { $('#externalLinksReport').poll(); }, 1000); + setTimeout(function() { $('#externalLinksReport').poll(0); }, 1000); } if (total && completed) { if (completed < total) { diff --git a/tests/ExternalLinksTest.php b/tests/ExternalLinksTest.php index 181365a..6c7bf61 100644 --- a/tests/ExternalLinksTest.php +++ b/tests/ExternalLinksTest.php @@ -7,7 +7,7 @@ class ExternalLinks extends FunctionalTest { public function testLinks() { // uses http://127.0.0.1 to test a working link $working = $this->objFromFixture('SiteTree', 'working'); - $working->publish('Stage', 'Stage'); + $working->write(); $task = new CheckExternalLinks(); $task->run(null); $brokenLinks = BrokenExternalLink::get()->column('Link');; @@ -18,7 +18,7 @@ class ExternalLinks extends FunctionalTest { public function testBrokenLink() { // uses http://192.0.2.1 for a broken link $broken = $this->objFromFixture('SiteTree', 'broken'); - $broken->publish('Stage', 'Stage'); + $broken->write(); $task = new CheckExternalLinks(); $task->run(null); $brokenLinks = BrokenExternalLink::get();