-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
helpfulrobot
committed
Dec 25, 2015
1 parent
fe8d93c
commit 4d08953
Showing
10 changed files
with
771 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,61 @@ | ||
<?php | ||
|
||
class CMSExternalLinks_Controller extends Controller { | ||
class CMSExternalLinks_Controller extends Controller | ||
{ | ||
|
||
private static $allowed_actions = array('getJobStatus', 'start'); | ||
private static $allowed_actions = array('getJobStatus', 'start'); | ||
|
||
/* | ||
* Respond to Ajax requests for info on a running job | ||
* | ||
* @return string JSON string detailing status of the job | ||
*/ | ||
public function getJobStatus() { | ||
// Set headers | ||
HTTP::set_cache_age(0); | ||
HTTP::add_cache_headers($this->response); | ||
$this->response | ||
->addHeader('Content-Type', 'application/json') | ||
->addHeader('Content-Encoding', 'UTF-8') | ||
->addHeader('X-Content-Type-Options', 'nosniff'); | ||
/* | ||
* Respond to Ajax requests for info on a running job | ||
* | ||
* @return string JSON string detailing status of the job | ||
*/ | ||
public function getJobStatus() | ||
{ | ||
// Set headers | ||
HTTP::set_cache_age(0); | ||
HTTP::add_cache_headers($this->response); | ||
$this->response | ||
->addHeader('Content-Type', 'application/json') | ||
->addHeader('Content-Encoding', 'UTF-8') | ||
->addHeader('X-Content-Type-Options', 'nosniff'); | ||
|
||
// Format status | ||
$track = BrokenExternalPageTrackStatus::get_latest(); | ||
if($track) return json_encode(array( | ||
'TrackID' => $track->ID, | ||
'Status' => $track->Status, | ||
'Completed' => $track->getCompletedPages(), | ||
'Total' => $track->getTotalPages() | ||
)); | ||
} | ||
// Format status | ||
$track = BrokenExternalPageTrackStatus::get_latest(); | ||
if ($track) { | ||
return json_encode(array( | ||
'TrackID' => $track->ID, | ||
'Status' => $track->Status, | ||
'Completed' => $track->getCompletedPages(), | ||
'Total' => $track->getTotalPages() | ||
)); | ||
} | ||
} | ||
|
||
|
||
/* | ||
* Starts a broken external link check | ||
*/ | ||
public function start() { | ||
// return if the a job is already running | ||
$status = BrokenExternalPageTrackStatus::get_latest(); | ||
if ($status && $status->Status == 'Running') return; | ||
/* | ||
* Starts a broken external link check | ||
*/ | ||
public function start() | ||
{ | ||
// return if the a job is already running | ||
$status = BrokenExternalPageTrackStatus::get_latest(); | ||
if ($status && $status->Status == 'Running') { | ||
return; | ||
} | ||
|
||
// Create a new job | ||
if (class_exists('QueuedJobService')) { | ||
// Force the creation of a new run | ||
BrokenExternalPageTrackStatus::create_status(); | ||
$checkLinks = new CheckExternalLinksJob(); | ||
singleton('QueuedJobService')->queueJob($checkLinks); | ||
} else { | ||
//TODO this hangs as it waits for the connection to be released | ||
// should return back and continue processing | ||
// http://us3.php.net/manual/en/features.connection-handling.php | ||
$task = CheckExternalLinksTask::create(); | ||
$task->runLinksCheck(); | ||
} | ||
} | ||
// Create a new job | ||
if (class_exists('QueuedJobService')) { | ||
// Force the creation of a new run | ||
BrokenExternalPageTrackStatus::create_status(); | ||
$checkLinks = new CheckExternalLinksJob(); | ||
singleton('QueuedJobService')->queueJob($checkLinks); | ||
} else { | ||
//TODO this hangs as it waits for the connection to be released | ||
// should return back and continue processing | ||
// http://us3.php.net/manual/en/features.connection-handling.php | ||
$task = CheckExternalLinksTask::create(); | ||
$task->runLinksCheck(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
<?php | ||
|
||
if(!class_exists('AbstractQueuedJob')) return; | ||
if (!class_exists('AbstractQueuedJob')) { | ||
return; | ||
} | ||
|
||
/** | ||
* A Job for running a external link check for published pages | ||
* | ||
*/ | ||
class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob { | ||
|
||
public function getTitle() { | ||
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links'); | ||
} | ||
class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob | ||
{ | ||
|
||
public function getJobType() { | ||
return QueuedJob::QUEUED; | ||
} | ||
public function getTitle() | ||
{ | ||
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links'); | ||
} | ||
|
||
public function getSignature() { | ||
return md5(get_class($this)); | ||
} | ||
public function getJobType() | ||
{ | ||
return QueuedJob::QUEUED; | ||
} | ||
|
||
/** | ||
* Check an individual page | ||
*/ | ||
public function process() { | ||
$task = CheckExternalLinksTask::create(); | ||
$track = $task->runLinksCheck(1); | ||
$this->currentStep = $track->CompletedPages; | ||
$this->totalSteps = $track->TotalPages; | ||
$this->isComplete = $track->Status === 'Completed'; | ||
} | ||
public function getSignature() | ||
{ | ||
return md5(get_class($this)); | ||
} | ||
|
||
/** | ||
* Check an individual page | ||
*/ | ||
public function process() | ||
{ | ||
$task = CheckExternalLinksTask::create(); | ||
$track = $task->runLinksCheck(1); | ||
$this->currentStep = $track->CompletedPages; | ||
$this->totalSteps = $track->TotalPages; | ||
$this->isComplete = $track->Status === 'Completed'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.