1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Document; |
4
|
|
|
|
5
|
|
|
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; |
9
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @MongoDB\Document(repositoryClass="App\Repositories\ProviderRepository") |
14
|
|
|
* @MongoDBUnique(fields="name") |
15
|
|
|
* @MongoDB\HasLifecycleCallbacks |
16
|
|
|
*/ |
17
|
|
|
class Provider |
18
|
|
|
{ |
19
|
|
|
const TYPE_COMPOSER = 'composer'; |
20
|
|
|
const TYPE_VCS = 'vcs'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @MongoDB\Id(strategy="NONE", type="string") |
24
|
|
|
* @Groups({"provider_default", "provider_full", "provider_write"}) |
25
|
|
|
* @Assert\NotBlank |
26
|
|
|
* @Assert\Regex(pattern="/^.*\/.*$/", message="The name of the package. It consists of vendor name and project name, separated by /") |
27
|
|
|
*/ |
28
|
|
|
protected $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @MongoDB\Field(type="string") |
32
|
|
|
* @MongoDB\Index() |
33
|
|
|
* |
34
|
|
|
* @Groups({"provider_default", "provider_full", "provider_write"}) |
35
|
|
|
* @Assert\Choice({Provider::TYPE_COMPOSER, Provider::TYPE_VCS}) |
36
|
|
|
* @Assert\NotBlank |
37
|
|
|
*/ |
38
|
|
|
protected $type; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @MongoDB\Field(type="string") |
42
|
|
|
* @Groups({"provider_default", "provider_full", "provider_write"}) |
43
|
|
|
* @Assert\Url |
44
|
|
|
*/ |
45
|
|
|
protected $vcsUri; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @MongoDB\Field(type="date") |
49
|
|
|
* @Groups({"provider_default", "provider_full"}) |
50
|
|
|
*/ |
51
|
|
|
protected $lastUpdate; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @MongoDB\Field(type="string") |
55
|
|
|
* @Groups({"provider_default", "provider_full"}) |
56
|
|
|
*/ |
57
|
|
|
protected $description; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @MongoDB\Field(type="string") |
61
|
|
|
*/ |
62
|
|
|
protected $sha256; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @MongoDB\Field(type="boolean") |
66
|
|
|
* @Groups({"provider_default", "provider_full"}) |
67
|
|
|
*/ |
68
|
|
|
protected $updateInProgress; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @MongoDB\Field(type="string") |
72
|
|
|
* @Groups({"provider_full"}) |
73
|
|
|
*/ |
74
|
|
|
protected $logs; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @MongoDB\Field(type="boolean") |
78
|
|
|
* @Groups({"provider_full"}) |
79
|
|
|
*/ |
80
|
|
|
protected $hasError; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @MongoDB\Field(type="int", strategy="increment") |
84
|
|
|
* @Groups({"provider_default", "provider_full"}) |
85
|
|
|
*/ |
86
|
|
|
protected $downloads; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @MongoDB\EmbedMany(targetDocument="Package") |
90
|
|
|
* @Groups({"provider_full"}) |
91
|
|
|
*/ |
92
|
|
|
private $packages; |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @MongoDB\Field(type="collection") |
97
|
|
|
*/ |
98
|
|
|
private $replace; |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function __construct() |
102
|
|
|
{ |
103
|
|
|
$this->packages = new ArrayCollection(); |
104
|
|
|
$this->updateInProgress = false; |
105
|
|
|
$this->downloads = 0; |
106
|
|
|
$this->hasError = false; |
107
|
|
|
$this->replace = []; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @MongoDB\PreFlush |
112
|
|
|
*/ |
113
|
|
|
public function onFlush() |
114
|
|
|
{ |
115
|
|
|
$this->setLastUpdate(new \DateTime()); |
116
|
|
|
|
117
|
|
|
if ($lastpackage = $this->packages->last()) { |
118
|
|
|
if (isset($lastpackage->getData()['description'])) { |
119
|
|
|
$this->setDescription($lastpackage->getData()['description']); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getName(): string |
125
|
|
|
{ |
126
|
|
|
return $this->name; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function setName(string $name): self |
130
|
|
|
{ |
131
|
|
|
$this->name = $name; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getType(): string |
137
|
|
|
{ |
138
|
|
|
return $this->type; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function setType(string $type): self |
142
|
|
|
{ |
143
|
|
|
$this->type = $type; |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getVcsUri(): ?string |
149
|
|
|
{ |
150
|
|
|
return $this->vcsUri; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setVcsUri(string $vcsUri): self |
154
|
|
|
{ |
155
|
|
|
$this->vcsUri = $vcsUri; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function getLastUpdate(): ?\DateTime |
161
|
|
|
{ |
162
|
|
|
return $this->lastUpdate; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function setLastUpdate(\DateTime $lastUpdate): self |
166
|
|
|
{ |
167
|
|
|
$this->lastUpdate = $lastUpdate; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getSha256(): string |
173
|
|
|
{ |
174
|
|
|
return $this->sha256; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setSha256(string $sha256): self |
178
|
|
|
{ |
179
|
|
|
$this->sha256 = $sha256; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function getDescription(): ?string |
185
|
|
|
{ |
186
|
|
|
return $this->description; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function setDescription(string $description): self |
190
|
|
|
{ |
191
|
|
|
$this->description = $description; |
192
|
|
|
|
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getUpdateInProgress(): bool |
197
|
|
|
{ |
198
|
|
|
return $this->updateInProgress; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function setUpdateInProgress(bool $updateInProgress): self |
202
|
|
|
{ |
203
|
|
|
$this->updateInProgress = $updateInProgress; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getLogs(): ?string |
209
|
|
|
{ |
210
|
|
|
return $this->logs; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function setLogs(?string $logs): self |
214
|
|
|
{ |
215
|
|
|
$this->logs = $logs; |
216
|
|
|
|
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getHasError(): bool |
221
|
|
|
{ |
222
|
|
|
return $this->hasError; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function setHasError(bool $hasError): self |
226
|
|
|
{ |
227
|
|
|
$this->hasError = $hasError; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function getDownloads(): ?int |
233
|
|
|
{ |
234
|
|
|
return $this->downloads; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function setDownloads(int $downloads): self |
238
|
|
|
{ |
239
|
|
|
$this->downloads = $downloads; |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function getPackages(): Collection |
245
|
|
|
{ |
246
|
|
|
return $this->packages; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function addPackage(Package $packages): self |
250
|
|
|
{ |
251
|
|
|
$this->packages->add($packages); |
252
|
|
|
|
253
|
|
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function removePackage(Package $packages): self |
257
|
|
|
{ |
258
|
|
|
$this->packages->remove($packages); |
259
|
|
|
|
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function clearPackages(): self |
264
|
|
|
{ |
265
|
|
|
$this->packages->clear(); |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function getReplace() :array |
271
|
|
|
{ |
272
|
|
|
return $this->replace; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function setReplace(array $replace): self |
276
|
|
|
{ |
277
|
|
|
$this->replace = $replace; |
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
} |
282
|
|
|
|