|
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); |
|
|
|
|
|
|
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
|
|
|
|