1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BringYourOwnIdeas\UpdateChecker\Extensions; |
4
|
|
|
|
5
|
|
|
use DataExtension; |
6
|
|
|
use Injector; |
7
|
|
|
use QueuedJobService; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Describes any available updates to an installed Composer package |
11
|
|
|
* |
12
|
|
|
* Originally from https://github.com/XploreNet/silverstripe-composerupdates |
13
|
|
|
*/ |
14
|
|
|
class ComposerUpdateExtension extends DataExtension |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $jobName = 'CheckComposerUpdatesJob'; |
20
|
|
|
|
21
|
|
|
private static $db = [ |
|
|
|
|
22
|
|
|
'VersionHash' => 'Varchar', |
23
|
|
|
'VersionConstraint' => 'Varchar(50)', |
24
|
|
|
'AvailableVersion' => 'Varchar(50)', |
25
|
|
|
'AvailableHash' => 'Varchar(50)', |
26
|
|
|
'LatestVersion' => 'Varchar(50)', |
27
|
|
|
'LatestHash' => 'Varchar(50)', |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
private static $summary_fields = [ |
|
|
|
|
31
|
|
|
'AvailableVersion' => 'Available', |
32
|
|
|
'LatestVersion' => 'Latest', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Automatically schedule a self update job on dev/build |
37
|
|
|
*/ |
38
|
|
|
public function requireDefaultRecords() |
39
|
|
|
{ |
40
|
|
|
$job = Injector::inst()->create($this->getJobName()); |
41
|
|
|
Injector::inst()->get(QueuedJobService::class)->queueJob($job); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* If the available version is the same as the current version then return nothing, otherwise show the latest |
46
|
|
|
* available version |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function getAvailableVersion() |
51
|
|
|
{ |
52
|
|
|
if ($this->owner->getField('Version') === $this->owner->getField('AvailableVersion')) { |
53
|
|
|
return ''; |
54
|
|
|
} |
55
|
|
|
return $this->owner->getField('AvailableVersion'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Return the name of the related job |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getJobName() |
64
|
|
|
{ |
65
|
|
|
return $this->jobName; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.