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.
Completed
Push — master ( 6956e2...9a55f0 )
by
unknown
02:08
created

CreateQueuedJobTask::run()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

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