1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Elastica\Document; |
4
|
|
|
use Elastica\Type\Mapping; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* An add-on with one or more versions. |
8
|
|
|
*/ |
9
|
|
|
class Addon extends DataObject { |
10
|
|
|
|
11
|
|
|
public static $db = array( |
12
|
|
|
'Name' => 'Varchar(255)', |
13
|
|
|
'Description' => 'Text', |
14
|
|
|
'Type' => 'Varchar(100)', |
15
|
|
|
'Readme' => 'HTMLText', |
16
|
|
|
'Released' => 'SS_Datetime', |
17
|
|
|
'Repository' => 'Varchar(255)', |
18
|
|
|
'Downloads' => 'Int', |
19
|
|
|
'DownloadsMonthly' => 'Int', |
20
|
|
|
'Favers' => 'Int', |
21
|
|
|
'LastUpdated' => 'SS_Datetime', |
22
|
|
|
'LastBuilt' => 'SS_Datetime', |
23
|
|
|
'BuildQueued' => 'Boolean', |
24
|
|
|
'HelpfulRobotData' => 'Text', |
25
|
|
|
'HelpfulRobotScore' => 'Int', |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
public static $has_one = array( |
29
|
|
|
'Vendor' => 'AddonVendor' |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
public static $has_many = array( |
33
|
|
|
'Versions' => 'AddonVersion' |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
public static $many_many = array( |
37
|
|
|
'Keywords' => 'AddonKeyword', |
38
|
|
|
'Screenshots' => 'Image', |
39
|
|
|
'CompatibleVersions' => 'SilverStripeVersion' |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
public static $default_sort = 'Name'; |
43
|
|
|
|
44
|
|
|
public static $extensions = array( |
45
|
|
|
'SilverStripe\\Elastica\\Searchable' |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Gets the addon's versions sorted from newest to oldest. |
50
|
|
|
* |
51
|
|
|
* @return ArrayList |
52
|
|
|
*/ |
53
|
|
|
public function SortedVersions() { |
54
|
|
|
$versions = $this->Versions()->toArray(); |
|
|
|
|
55
|
|
|
|
56
|
|
|
usort($versions, function($a, $b) { |
57
|
|
|
return version_compare($b->Version, $a->Version); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
return new ArrayList($versions); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function MasterVersion() { |
64
|
|
|
return $this->Versions()->filter('PrettyVersion', array('dev-master', 'trunk'))->First(); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function Authors() { |
68
|
|
|
return $this->Versions()->relation('Authors'); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function VendorName() { |
72
|
|
|
return substr($this->Name, 0, strpos($this->Name, '/')); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function VendorLink() { |
76
|
|
|
return Controller::join_links( |
77
|
|
|
Director::baseURL(), 'add-ons', $this->VendorName() |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function PackageName() { |
82
|
|
|
return substr($this->Name, strpos($this->Name, '/') + 1); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function Link() { |
86
|
|
|
return Controller::join_links( |
87
|
|
|
Director::baseURL(), 'add-ons', $this->Name |
|
|
|
|
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function DescriptionText() { |
92
|
|
|
return $this->Description; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function RSSTitle() { |
96
|
|
|
return sprintf('New module release: %s', $this->Name); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function PackagistUrl() { |
100
|
|
|
return "https://packagist.org/packages/$this->Name"; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getElasticaMapping() { |
104
|
|
|
return new Mapping(null, array( |
105
|
|
|
'name' => array('type' => 'string'), |
106
|
|
|
'description' => array('type' => 'string'), |
107
|
|
|
'type' => array('type' => 'string'), |
108
|
|
|
'compatibility' => array('type' => 'string'), |
109
|
|
|
'vendor' => array('type' => 'string'), |
110
|
|
|
'tags' => array('type' => 'string'), |
111
|
|
|
'released' => array('type' => 'date'), |
112
|
|
|
'downloads' => array('type' => 'string'), |
113
|
|
|
'readme' => array('type' => 'string') |
114
|
|
|
)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getElasticaDocument() { |
118
|
|
|
return new Document($this->ID, array( |
119
|
|
|
'name' => $this->Name, |
|
|
|
|
120
|
|
|
'description' => $this->Description, |
|
|
|
|
121
|
|
|
'type' => $this->Type, |
|
|
|
|
122
|
|
|
'compatibility' => $this->CompatibleVersions()->column('Name'), |
|
|
|
|
123
|
|
|
'vendor' => $this->VendorName(), |
124
|
|
|
'tags' => $this->Keywords()->column('Name'), |
|
|
|
|
125
|
|
|
'released' => $this->obj('Released')->Format('c'), |
126
|
|
|
'downloads' => (int) $this->Downloads, |
|
|
|
|
127
|
|
|
'readme' => strip_tags($this->Readme), |
|
|
|
|
128
|
|
|
'_boost' => sqrt($this->Downloads) |
|
|
|
|
129
|
|
|
)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function onBeforeDelete() { |
133
|
|
|
parent::onBeforeDelete(); |
134
|
|
|
|
135
|
|
|
// Partially cascade delete. Leave author and keywords in place, |
136
|
|
|
// since they might be related to other addons. |
137
|
|
|
foreach($this->Screenshots() as $image) { |
|
|
|
|
138
|
|
|
$image->delete(); |
139
|
|
|
} |
140
|
|
|
$this->Screenshots()->removeAll(); |
|
|
|
|
141
|
|
|
|
142
|
|
|
foreach($this->Versions() as $version) { |
|
|
|
|
143
|
|
|
$version->delete(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$this->Keywords()->removeAll(); |
|
|
|
|
147
|
|
|
$this->CompatibleVersions()->removeAll(); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getDateCreated() { |
151
|
|
|
return date('Y-m-d', strtotime($this->Created)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
|
|
public function HelpfulRobotData() |
158
|
|
|
{ |
159
|
|
|
return json_decode($this->HelpfulRobotData, true); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.