Completed
Pull Request — master (#93)
by
unknown
02:31
created

CheckForUpdatesJob::afterComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace BringYourOwnIdeas\Maintenance\Jobs;
4
5
use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask;
6
use DateTime;
7
use SilverStripe\Core\Injector\Injector;
8
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
9
use Symbiote\QueuedJobs\Services\QueuedJob;
10
use Symbiote\QueuedJobs\Services\QueuedJobService;
11
12
/**
13
 * Refresh report job. Runs as a queued job.
14
 *
15
 */
16
class CheckForUpdatesJob extends AbstractQueuedJob implements QueuedJob
17
{
18
    /**
19
     * Define the title
20
     *
21
     * @return string
22
     */
23
    public function getTitle()
24
    {
25
        return _t(__CLASS__ . '.TITLE', 'Check for updates to installed modules');
26
    }
27
28
    /**
29
     * Define the type.
30
     */
31
    public function getJobType()
32
    {
33
        $this->totalSteps = 1;
34
        return QueuedJob::QUEUED;
35
    }
36
37
    /**
38
     * Create the instance of the task
39
     */
40
    public function setup()
41
    {
42
        $this->task = Injector::inst()->create(CheckForUpdatesJob::class);
0 ignored issues
show
Bug Best Practice introduced by
The property task does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
    }
44
45
    /**
46
     * Processes the task as a job
47
     */
48
    public function process()
49
    {
50
        // Run the UpdatePackageInfo task
51
        $updateTask = Injector::inst()->create(UpdatePackageInfoTask::class);
52
        $updateTask->run(null);
53
54
        // mark job as completed
55
        $this->isComplete = true;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function afterComplete()
62
    {
63
        // Queue a new job to run in the future
64
        $injector = Injector::inst();
65
        $queuedJobService = $injector->get(QueuedJobService::class);
66
        $startAfter = new DateTime('+24 hours');
67
        $queuedJobService->queueJob(
68
            $injector->create(CheckForUpdatesJob::class),
69
            $startAfter->format(DateTime::ISO8601)
70
        );
71
    }
72
}
73