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