GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CreateQueuedJobTask::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks;
4
5
use SilverStripe\Control\HTTPRequest;
6
use SilverStripe\Core\ClassInfo;
7
use SilverStripe\Dev\BuildTask;
8
use SilverStripe\ORM\FieldType\DBDatetime;
9
use Symbiote\QueuedJobs\Services\QueuedJobService;
10
11
/**
12
 * A task that can be used to create a queued job.
13
 *
14
 * Useful to hook a queued job in to place that needs to exist if it doesn't already.
15
 *
16
 * If no name is given, it creates a demo dummy job to help test that things
17
 * are set up and working
18
 *
19
 * @author Marcus Nyeholt <[email protected]>
20
 * @license BSD http://silverstripe.org/bsd-license/
21
 */
22
class CreateQueuedJobTask extends BuildTask
23
{
24
    /**
25
     * {@inheritDoc}
26
     * @var string
27
     */
28
    private static $segment = 'CreateQueuedJobTask';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
29
30
    /**
31
     * @return string
32
     */
33
    public function getDescription()
34
    {
35
        return _t(
36
            __CLASS__ . '.Description',
37
            'A task used to create a queued job. Pass the queued job class name as the "name" parameter, '
38
            . 'pass an optional "start" parameter (parseable by strtotime) to set a start time for the job.'
39
        );
40
    }
41
42
    /**
43
     * @param HTTPRequest $request
44
     */
45
    public function run($request)
46
    {
47
        if (isset($request['name']) && ClassInfo::exists($request['name'])) {
48
            $clz = $request['name'];
49
            $job = new $clz();
50
        } else {
51
            $job = new DummyQueuedJob(mt_rand(10, 100));
52
        }
53
54
        if (isset($request['start'])) {
55
            $start = strtotime($request['start']);
56
            $now = DBDatetime::now()->getTimestamp();
57
            if ($start >= $now) {
58
                $friendlyStart = DBDatetime::create()->setValue($start)->Rfc2822();
59
                echo "Job " . $request['name'] . " queued to start at: <b>" . $friendlyStart . "</b>";
60
                QueuedJobService::singleton()->queueJob($job, $start);
61
            } else {
62
                echo "'start' parameter must be a date/time in the future, parseable with strtotime";
63
            }
64
        } else {
65
            echo "Job Queued";
66
            QueuedJobService::singleton()->queueJob($job);
67
        }
68
    }
69
}
70