1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Updates the available SilverStripe versions. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
use Composer\Package\Version\VersionParser; |
7
|
|
|
|
8
|
|
|
class SilverStripeVersionUpdater |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var PackagistService |
13
|
|
|
*/ |
14
|
|
|
private $packagist; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @config |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $versionBlacklist = array('2.5.x-dev'); |
21
|
|
|
|
22
|
|
|
public function __construct(PackagistService $packagist) |
23
|
|
|
{ |
24
|
|
|
$this->packagist = $packagist; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function update() |
28
|
|
|
{ |
29
|
|
|
$versions = $this->packagist->getPackageVersions('silverstripe/framework'); |
30
|
|
|
|
31
|
|
|
foreach ($versions as $package) { |
32
|
|
|
$version = $package->getVersion(); |
33
|
|
|
|
34
|
|
|
// Replace version by branch alias if applicable |
35
|
|
|
$extra = $package->getExtra(); |
36
|
|
|
if (isset($extra['branch-alias'][$version])) { |
37
|
|
|
$version = $extra['branch-alias'][$version]; |
38
|
|
|
} |
39
|
|
|
$stability = VersionParser::parseStability($version); |
40
|
|
|
|
41
|
|
|
$isDev = $stability === 'dev'; |
42
|
|
|
|
43
|
|
|
if (!$isDev || in_array($version, $this->versionBlacklist)) { |
44
|
|
|
continue; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$match = preg_match( |
48
|
|
|
'/^([0-9]+)\.([0-9]+)\.x-dev$/', |
49
|
|
|
$version, |
50
|
|
|
$matches |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
if (!$match) { |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$major = $matches[1]; |
58
|
|
|
$minor = $matches[2]; |
59
|
|
|
|
60
|
|
|
$record = SilverStripeVersion::get() |
61
|
|
|
->filter('Major', $major) |
62
|
|
|
->filter('Minor', $minor) |
63
|
|
|
->first(); |
64
|
|
|
|
65
|
|
|
if (!$record) { |
66
|
|
|
$record = new SilverStripeVersion(); |
67
|
|
|
$record->Name = "$major.$minor"; |
|
|
|
|
68
|
|
|
$record->Major = $major; |
|
|
|
|
69
|
|
|
$record->Minor = $minor; |
|
|
|
|
70
|
|
|
$record->write(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setVersionBlacklist($list) |
76
|
|
|
{ |
77
|
|
|
$this->versionBlacklist = $list; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getVersionBlacklist() |
81
|
|
|
{ |
82
|
|
|
return $this->versionBlacklist; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.