LDAPMemberSyncJob::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The property $regenerate_time is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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