2014-07-28 01:23:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CMSExternalLinks_Controller extends Controller {
|
|
|
|
|
2014-07-31 06:49:20 +02:00
|
|
|
private static $allowed_actions = array('getJobStatus', 'start');
|
2014-07-28 01:23:33 +02:00
|
|
|
|
2014-07-30 02:34:39 +02:00
|
|
|
/*
|
|
|
|
* Respond to Ajax requests for info on a running job
|
|
|
|
*
|
|
|
|
* @return string JSON string detailing status of the job
|
|
|
|
*/
|
|
|
|
public function getJobStatus() {
|
2014-08-07 03:56:15 +02:00
|
|
|
// 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(
|
2014-07-31 06:49:20 +02:00
|
|
|
'TrackID' => $track->ID,
|
|
|
|
'Status' => $track->Status,
|
2014-08-07 03:56:15 +02:00
|
|
|
'Completed' => $track->getCompletedPages(),
|
|
|
|
'Total' => $track->getTotalPages()
|
2014-07-30 02:34:39 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Starts a broken external link check
|
|
|
|
*/
|
|
|
|
public function start() {
|
2014-07-31 06:49:20 +02:00
|
|
|
// return if the a job is already running
|
2014-08-07 03:56:15 +02:00
|
|
|
$status = BrokenExternalPageTrackStatus::get_latest();
|
|
|
|
if ($status && $status->Status == 'Running') return;
|
2014-08-04 07:38:28 +02:00
|
|
|
|
2014-08-07 03:56:15 +02:00
|
|
|
// Create a new job
|
|
|
|
if (class_exists('QueuedJobService')) {
|
|
|
|
// Force the creation of a new run
|
|
|
|
BrokenExternalPageTrackStatus::create_status();
|
2014-07-31 06:49:20 +02:00
|
|
|
$checkLinks = new CheckExternalLinksJob();
|
2014-08-07 03:56:15 +02:00
|
|
|
singleton('QueuedJobService')->queueJob($checkLinks);
|
2014-07-31 06:49:20 +02:00
|
|
|
} else {
|
|
|
|
//TODO this hangs as it waits for the connection to be released
|
2014-08-07 03:56:15 +02:00
|
|
|
// should return back and continue processing
|
2014-07-31 06:49:20 +02:00
|
|
|
// http://us3.php.net/manual/en/features.connection-handling.php
|
2014-08-07 03:56:15 +02:00
|
|
|
$task = CheckExternalLinksTask::create();
|
|
|
|
$task->runLinksCheck();
|
2014-07-31 06:49:20 +02:00
|
|
|
}
|
2014-07-28 01:23:33 +02:00
|
|
|
}
|
|
|
|
}
|