1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class LDAPMemberSyncJob |
4
|
|
|
* |
5
|
|
|
* A {@link QueuedJob} job to sync all users to the site using LDAP. |
6
|
|
|
* This doesn't do the actual sync work, but rather just triggers {@link LDAPMemberSyncTask} |
7
|
|
|
*/ |
8
|
|
|
class LDAPMemberSyncJob extends AbstractQueuedJob |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* If you specify this value in seconds, it tells the completed job to queue another of itself |
12
|
|
|
* x seconds ahead of time. |
13
|
|
|
* |
14
|
|
|
* @var mixed |
15
|
|
|
* @config |
16
|
|
|
*/ |
17
|
|
|
private static $regenerate_time = null; |
|
|
|
|
18
|
|
|
|
19
|
|
|
public function __construct() |
20
|
|
|
{ |
21
|
|
|
// noop, but needed for QueuedJobsAdmin::createjob() to work |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getJobType() |
25
|
|
|
{ |
26
|
|
|
return QueuedJob::QUEUED; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getTitle() |
30
|
|
|
{ |
31
|
|
|
return _t('LDAPMemberSyncJob.SYNCTITLE', 'Sync all users from Active Directory'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getSignature() |
35
|
|
|
{ |
36
|
|
|
return md5(get_class($this)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function validateRegenerateTime() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$regenerateTime = Config::inst()->get('LDAPMemberSyncJob', 'regenerate_time'); |
42
|
|
|
|
43
|
|
|
// don't allow this job to run less than every 15 minutes, as it could take a while. |
44
|
|
|
if ($regenerateTime !== null && $regenerateTime < 900) { |
45
|
|
|
throw new Exception('LDAPMemberSyncJob::regenerate_time must be 15 minutes or greater'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function process() |
50
|
|
|
{ |
51
|
|
|
$regenerateTime = Config::inst()->get('LDAPMemberSyncJob', 'regenerate_time'); |
52
|
|
View Code Duplication |
if ($regenerateTime) { |
|
|
|
|
53
|
|
|
$this->validateRegenerateTime(); |
54
|
|
|
|
55
|
|
|
$nextJob = Injector::inst()->create('LDAPMemberSyncJob'); |
56
|
|
|
singleton('QueuedJobService')->queueJob($nextJob, date('Y-m-d H:i:s', time() + $regenerateTime)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$task = Injector::inst()->create('LDAPMemberSyncTask'); |
60
|
|
|
$task->run(null); |
61
|
|
|
|
62
|
|
|
$this->isComplete = true; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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.