1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* A version of an add-on package. |
4
|
|
|
*/ |
5
|
|
|
class AddonVersion extends DataObject |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
public static $db = array( |
9
|
|
|
'Name' => 'Varchar(255)', |
10
|
|
|
'Description' => 'Text', |
11
|
|
|
'Type' => 'Varchar(100)', |
12
|
|
|
'Released' => 'SS_Datetime', |
13
|
|
|
'Extra' => 'MultiValueField', |
14
|
|
|
'Homepage' => 'Varchar(255)', |
15
|
|
|
'Version' => 'Varchar(100)', |
16
|
|
|
'PrettyVersion' => 'Varchar(100)', |
17
|
|
|
'Development' => 'Boolean', |
18
|
|
|
'License' => 'MultiValueField', |
19
|
|
|
'SourceType' => 'Varchar(100)', |
20
|
|
|
'SourceUrl' => 'Varchar(255)', |
21
|
|
|
'SourceReference' => 'Varchar(40)', |
22
|
|
|
'DistType' => 'Varchar(100)', |
23
|
|
|
'DistUrl' => 'Varchar(255)', |
24
|
|
|
'DistReference' => 'Varchar(100)', |
25
|
|
|
'DistChecksum' => 'Varchar(40)', |
26
|
|
|
'Dist' => 'MultiValueField', |
27
|
|
|
'Support' => 'MultiValueField' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
public static $has_one = array( |
31
|
|
|
'Addon' => 'Addon' |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
public static $has_many = array( |
35
|
|
|
'Links' => 'AddonLink' |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
public static $many_many = array( |
39
|
|
|
'Authors' => 'AddonAuthor', |
40
|
|
|
'Keywords' => 'AddonKeyword', |
41
|
|
|
'CompatibleVersions' => 'SilverStripeVersion' |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
public static $default_sort = array( |
45
|
|
|
'ID' => 'DESC' |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
private static $summary_fields = array( |
|
|
|
|
49
|
|
|
'PrettyVersion' => 'Version', |
50
|
|
|
'Description' => 'Description' |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
public function DisplayVersion() |
54
|
|
|
{ |
55
|
|
|
return $this->PrettyVersion; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function DisplayRequireVersion() |
59
|
|
|
{ |
60
|
|
|
return str_replace('.x-dev', '.*@dev', $this->DisplayVersion()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Fallback to SourceUrl with normalized github links. |
65
|
|
|
*/ |
66
|
|
|
public function DisplayHomepage() |
67
|
|
|
{ |
68
|
|
|
if ($this->Homepage) { |
|
|
|
|
69
|
|
|
return $this->Homepage; |
|
|
|
|
70
|
|
|
} else { |
71
|
|
|
return str_replace( |
72
|
|
|
array('git://github.com', '[email protected]'), |
73
|
|
|
'https://github.com', |
74
|
|
|
$this->SourceUrl |
|
|
|
|
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getRequires() |
80
|
|
|
{ |
81
|
|
|
return $this->Links()->filter('Type', 'require'); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getRequiresDev() |
85
|
|
|
{ |
86
|
|
|
return $this->Links()->filter('Type', 'require-dev'); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getSuggests() |
90
|
|
|
{ |
91
|
|
|
return $this->Links()->filter('Type', 'suggest'); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getProvides() |
95
|
|
|
{ |
96
|
|
|
return $this->Links()->filter('Type', 'provide'); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getConflicts() |
100
|
|
|
{ |
101
|
|
|
return $this->Links()->filter('Type', 'conflict'); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getReplaces() |
105
|
|
|
{ |
106
|
|
|
return $this->Links()->filter('Type', 'replace'); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function InstallLink() |
110
|
|
|
{ |
111
|
|
|
return Controller::join_links($this->Addon()->Link(), 'install', $this->ID); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function onBeforeDelete() |
115
|
|
|
{ |
116
|
|
|
parent::onBeforeDelete(); |
117
|
|
|
|
118
|
|
|
// Remove our relations but leave the related objects for objects |
119
|
|
|
// that may be used by other objects. |
120
|
|
|
foreach ($this->Links() as $link) { |
|
|
|
|
121
|
|
|
$link->delete(); |
122
|
|
|
} |
123
|
|
|
$this->Authors()->removeAll(); |
|
|
|
|
124
|
|
|
$this->Keywords()->removeAll(); |
|
|
|
|
125
|
|
|
$this->CompatibleVersions()->removeAll(); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|