1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CMSExternalLinks_Controller extends Controller |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
private static $allowed_actions = array('getJobStatus', 'start'); |
|
|
|
|
7
|
|
|
|
8
|
|
|
/* |
9
|
|
|
* Respond to Ajax requests for info on a running job |
10
|
|
|
* |
11
|
|
|
* @return string JSON string detailing status of the job |
12
|
|
|
*/ |
13
|
|
|
public function getJobStatus() |
14
|
|
|
{ |
15
|
|
|
// Set headers |
16
|
|
|
HTTP::set_cache_age(0); |
17
|
|
|
HTTP::add_cache_headers($this->response); |
18
|
|
|
$this->response |
19
|
|
|
->addHeader('Content-Type', 'application/json') |
20
|
|
|
->addHeader('Content-Encoding', 'UTF-8') |
21
|
|
|
->addHeader('X-Content-Type-Options', 'nosniff'); |
22
|
|
|
|
23
|
|
|
// Format status |
24
|
|
|
$track = BrokenExternalPageTrackStatus::get_latest(); |
25
|
|
|
if ($track) { |
26
|
|
|
return json_encode(array( |
27
|
|
|
'TrackID' => $track->ID, |
28
|
|
|
'Status' => $track->Status, |
|
|
|
|
29
|
|
|
'Completed' => $track->getCompletedPages(), |
30
|
|
|
'Total' => $track->getTotalPages() |
31
|
|
|
)); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/* |
37
|
|
|
* Starts a broken external link check |
38
|
|
|
*/ |
39
|
|
|
public function start() |
40
|
|
|
{ |
41
|
|
|
// return if the a job is already running |
42
|
|
|
$status = BrokenExternalPageTrackStatus::get_latest(); |
43
|
|
|
if ($status && $status->Status == 'Running') { |
|
|
|
|
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Create a new job |
48
|
|
|
if (class_exists('QueuedJobService')) { |
49
|
|
|
// Force the creation of a new run |
50
|
|
|
BrokenExternalPageTrackStatus::create_status(); |
51
|
|
|
$checkLinks = new CheckExternalLinksJob(); |
52
|
|
|
singleton('QueuedJobService')->queueJob($checkLinks); |
53
|
|
|
} else { |
54
|
|
|
//TODO this hangs as it waits for the connection to be released |
55
|
|
|
// should return back and continue processing |
56
|
|
|
// http://us3.php.net/manual/en/features.connection-handling.php |
57
|
|
|
$task = CheckExternalLinksTask::create(); |
58
|
|
|
$task->runLinksCheck(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.