1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fabrica\Models\Infra\Ci\Base; |
4
|
|
|
|
5
|
|
|
use Pedreiro\Exceptions\InvalidArgumentException; |
6
|
|
|
use Pedreiro\Models\Base; |
7
|
|
|
use Fabrica\Tools\Store\BuildStore; |
8
|
|
|
use Fabrica\Tools\Store\Factory; |
9
|
|
|
|
10
|
|
|
class Build extends Base |
11
|
|
|
{ |
12
|
|
|
const STATUS_PENDING = 0; |
13
|
|
|
const STATUS_RUNNING = 1; |
14
|
|
|
const STATUS_SUCCESS = 2; |
15
|
|
|
const STATUS_FAILED = 3; |
16
|
|
|
|
17
|
|
|
const SOURCE_UNKNOWN = 0; |
18
|
|
|
const SOURCE_MANUAL_WEB = 1; |
19
|
|
|
const SOURCE_MANUAL_CONSOLE = 2; |
20
|
|
|
const SOURCE_PERIODICAL = 3; |
21
|
|
|
const SOURCE_WEBHOOK_PUSH = 4; |
22
|
|
|
const SOURCE_WEBHOOK_PULL_REQUEST_CREATED = 5; |
23
|
|
|
const SOURCE_WEBHOOK_PULL_REQUEST_UPDATED = 6; |
24
|
|
|
const SOURCE_WEBHOOK_PULL_REQUEST_APPROVED = 7; |
25
|
|
|
const SOURCE_WEBHOOK_PULL_REQUEST_MERGED = 8; |
26
|
|
|
const SOURCE_MANUAL_REBUILD_WEB = 9; |
27
|
|
|
const SOURCE_MANUAL_REBUILD_CONSOLE = 10; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $data = [ |
33
|
|
|
'id' => null, |
34
|
|
|
'parent_id' => 0, |
35
|
|
|
'project_id' => null, |
36
|
|
|
'commit_id' => null, |
37
|
|
|
'status' => null, |
38
|
|
|
'log' => null, |
39
|
|
|
'branch' => 'master', |
40
|
|
|
'tag' => null, |
41
|
|
|
'create_date' => null, |
42
|
|
|
'start_date' => null, |
43
|
|
|
'finish_date' => null, |
44
|
|
|
'committer_email' => null, |
45
|
|
|
'commit_message' => null, |
46
|
|
|
'extra' => null, |
47
|
|
|
'environment' => null, |
48
|
|
|
'source' => Build::SOURCE_UNKNOWN, |
49
|
|
|
'user_id' => 0, |
50
|
|
|
'errors_total' => null, |
51
|
|
|
'errors_total_previous' => null, |
52
|
|
|
'errors_new' => null, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $allowedStatuses = [ |
59
|
|
|
self::STATUS_PENDING, |
60
|
|
|
self::STATUS_RUNNING, |
61
|
|
|
self::STATUS_SUCCESS, |
62
|
|
|
self::STATUS_FAILED, |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $allowedSources = [ |
69
|
|
|
self::SOURCE_UNKNOWN, |
70
|
|
|
self::SOURCE_MANUAL_WEB, |
71
|
|
|
self::SOURCE_MANUAL_CONSOLE, |
72
|
|
|
self::SOURCE_MANUAL_REBUILD_WEB, |
73
|
|
|
self::SOURCE_MANUAL_REBUILD_CONSOLE, |
74
|
|
|
self::SOURCE_PERIODICAL, |
75
|
|
|
self::SOURCE_WEBHOOK_PUSH, |
76
|
|
|
self::SOURCE_WEBHOOK_PULL_REQUEST_CREATED, |
77
|
|
|
self::SOURCE_WEBHOOK_PULL_REQUEST_UPDATED, |
78
|
|
|
self::SOURCE_WEBHOOK_PULL_REQUEST_APPROVED, |
79
|
|
|
self::SOURCE_WEBHOOK_PULL_REQUEST_MERGED, |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
public function getId() |
86
|
|
|
{ |
87
|
|
|
return (int)$this->data['id']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param int $value |
92
|
|
|
* |
93
|
|
|
* @return bool |
94
|
|
|
* |
95
|
|
|
* @throws InvalidArgumentException |
96
|
|
|
*/ |
97
|
|
|
public function setId($value) |
98
|
|
|
{ |
99
|
|
|
$this->validateNotNull('id', $value); |
100
|
|
|
$this->validateInt('id', $value); |
101
|
|
|
|
102
|
|
|
if ($this->data['id'] === $value) { |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->data['id'] = (int)$value; |
107
|
|
|
|
108
|
|
|
return $this->setModified('id'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return int |
113
|
|
|
*/ |
114
|
|
|
public function getParentId() |
115
|
|
|
{ |
116
|
|
|
return (integer)$this->data['parent_id']; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $value |
121
|
|
|
* |
122
|
|
|
* @return bool |
123
|
|
|
* |
124
|
|
|
* @throws InvalidArgumentException |
125
|
|
|
*/ |
126
|
|
|
public function setParentId($value) |
127
|
|
|
{ |
128
|
|
|
$this->validateNotNull('parent_id', $value); |
129
|
|
|
$this->validateInt('parent_id', $value); |
130
|
|
|
|
131
|
|
|
if ($this->data['parent_id'] === $value) { |
132
|
|
|
return false; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->data['parent_id'] = $value; |
136
|
|
|
|
137
|
|
|
return $this->setModified('parent_id'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return int |
142
|
|
|
*/ |
143
|
|
|
public function getProjectId() |
144
|
|
|
{ |
145
|
|
|
return (int)$this->data['project_id']; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param int $value |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
* |
153
|
|
|
* @throws InvalidArgumentException |
154
|
|
|
*/ |
155
|
|
|
public function setProjectId($value) |
156
|
|
|
{ |
157
|
|
|
$this->validateNotNull('project_id', $value); |
158
|
|
|
$this->validateInt('project_id', $value); |
159
|
|
|
|
160
|
|
|
if ($this->data['project_id'] === $value) { |
161
|
|
|
return false; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$this->data['project_id'] = $value; |
165
|
|
|
|
166
|
|
|
return $this->setModified('project_id'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function getCommitId() |
173
|
|
|
{ |
174
|
|
|
return $this->data['commit_id']; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $value |
179
|
|
|
* |
180
|
|
|
* @return bool |
181
|
|
|
* |
182
|
|
|
* @throws InvalidArgumentException |
183
|
|
|
*/ |
184
|
|
View Code Duplication |
public function setCommitId($value) |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
$this->validateNotNull('commit_id', $value); |
187
|
|
|
$this->validateString('commit_id', $value); |
188
|
|
|
|
189
|
|
|
if ($this->data['commit_id'] === $value) { |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$this->data['commit_id'] = $value; |
194
|
|
|
|
195
|
|
|
return $this->setModified('commit_id'); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return int |
200
|
|
|
*/ |
201
|
|
|
public function getStatus() |
202
|
|
|
{ |
203
|
|
|
return (int)$this->data['status']; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param int $value |
208
|
|
|
* |
209
|
|
|
* @return bool |
210
|
|
|
* |
211
|
|
|
* @throws InvalidArgumentException |
212
|
|
|
*/ |
213
|
|
View Code Duplication |
public function setStatus($value) |
|
|
|
|
214
|
|
|
{ |
215
|
|
|
$this->validateNotNull('status', $value); |
216
|
|
|
$this->validateInt('status', $value); |
217
|
|
|
|
218
|
|
|
if (!in_array($value, $this->allowedStatuses, true)) { |
219
|
|
|
throw new InvalidArgumentException( |
220
|
|
|
'Column "status" must be one of: ' . join(', ', $this->allowedStatuses) . '.' |
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if ($this->data['status'] === $value) { |
225
|
|
|
return false; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$this->data['status'] = $value; |
229
|
|
|
|
230
|
|
|
return $this->setModified('status'); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
View Code Duplication |
public function setStatusPending() |
|
|
|
|
234
|
|
|
{ |
235
|
|
|
if (self::STATUS_PENDING !== $this->data['status']) { |
236
|
|
|
$this->setModified('status'); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$this->data['status'] = self::STATUS_PENDING; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
View Code Duplication |
public function setStatusRunning() |
|
|
|
|
243
|
|
|
{ |
244
|
|
|
if (self::STATUS_RUNNING !== $this->data['status']) { |
245
|
|
|
$this->setModified('status'); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$this->data['status'] = self::STATUS_RUNNING; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
View Code Duplication |
public function setStatusSuccess() |
|
|
|
|
252
|
|
|
{ |
253
|
|
|
if (self::STATUS_SUCCESS !== $this->data['status']) { |
254
|
|
|
$this->setModified('status'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
$this->data['status'] = self::STATUS_SUCCESS; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
View Code Duplication |
public function setStatusFailed() |
|
|
|
|
261
|
|
|
{ |
262
|
|
|
if (self::STATUS_FAILED !== $this->data['status']) { |
263
|
|
|
$this->setModified('status'); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$this->data['status'] = self::STATUS_FAILED; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return string |
271
|
|
|
*/ |
272
|
|
|
public function getLog() |
273
|
|
|
{ |
274
|
|
|
return $this->data['log']; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param string|null $value |
279
|
|
|
* |
280
|
|
|
* @return bool |
281
|
|
|
* |
282
|
|
|
* @throws InvalidArgumentException |
283
|
|
|
*/ |
284
|
|
View Code Duplication |
public function setLog($value) |
|
|
|
|
285
|
|
|
{ |
286
|
|
|
$this->validateString('log', $value); |
287
|
|
|
|
288
|
|
|
if ($this->data['log'] === $value) { |
289
|
|
|
return false; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
$this->data['log'] = $value; |
293
|
|
|
|
294
|
|
|
return $this->setModified('log'); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return string |
299
|
|
|
*/ |
300
|
|
|
public function getBranch() |
301
|
|
|
{ |
302
|
|
|
return $this->data['branch']; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @param string $value |
307
|
|
|
* |
308
|
|
|
* @return bool |
309
|
|
|
* |
310
|
|
|
* @throws InvalidArgumentException |
311
|
|
|
*/ |
312
|
|
View Code Duplication |
public function setBranch($value) |
|
|
|
|
313
|
|
|
{ |
314
|
|
|
$this->validateNotNull('branch', $value); |
315
|
|
|
$this->validateString('branch', $value); |
316
|
|
|
|
317
|
|
|
if ($this->data['branch'] === $value) { |
318
|
|
|
return false; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
$this->data['branch'] = $value; |
322
|
|
|
|
323
|
|
|
return $this->setModified('branch'); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return string |
328
|
|
|
*/ |
329
|
|
|
public function getTag() |
330
|
|
|
{ |
331
|
|
|
return $this->data['tag']; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @param string|null $value |
336
|
|
|
* |
337
|
|
|
* @return bool |
338
|
|
|
* |
339
|
|
|
* @throws InvalidArgumentException |
340
|
|
|
*/ |
341
|
|
View Code Duplication |
public function setTag($value) |
|
|
|
|
342
|
|
|
{ |
343
|
|
|
$this->validateString('tag', $value); |
344
|
|
|
|
345
|
|
|
if ($this->data['tag'] === $value) { |
346
|
|
|
return false; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$this->data['tag'] = $value; |
350
|
|
|
|
351
|
|
|
return $this->setModified('tag'); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @return \DateTime|null |
356
|
|
|
* |
357
|
|
|
* @throws \Exception |
358
|
|
|
*/ |
359
|
|
|
public function getCreateDate() |
360
|
|
|
{ |
361
|
|
|
if ($this->data['create_date']) { |
362
|
|
|
return new \DateTime($this->data['create_date']); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
return null; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @param \DateTime $value |
370
|
|
|
* |
371
|
|
|
* @return bool |
372
|
|
|
*/ |
373
|
|
View Code Duplication |
public function setCreateDate(\DateTime $value) |
|
|
|
|
374
|
|
|
{ |
375
|
|
|
$stringValue = $value->format('Y-m-d H:i:s'); |
376
|
|
|
|
377
|
|
|
if ($this->data['create_date'] === $stringValue) { |
378
|
|
|
return false; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$this->data['create_date'] = $stringValue; |
382
|
|
|
|
383
|
|
|
return $this->setModified('create_date'); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return \DateTime|null |
388
|
|
|
* |
389
|
|
|
* @throws \Exception |
390
|
|
|
*/ |
391
|
|
|
public function getStartDate() |
392
|
|
|
{ |
393
|
|
|
if ($this->data['start_date']) { |
394
|
|
|
return new \DateTime($this->data['start_date']); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
return null; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @param \DateTime $value |
402
|
|
|
* |
403
|
|
|
* @return bool |
404
|
|
|
*/ |
405
|
|
View Code Duplication |
public function setStartDate(\DateTime $value) |
|
|
|
|
406
|
|
|
{ |
407
|
|
|
$stringValue = $value->format('Y-m-d H:i:s'); |
408
|
|
|
|
409
|
|
|
if ($this->data['start_date'] === $stringValue) { |
410
|
|
|
return false; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
$this->data['start_date'] = $stringValue; |
414
|
|
|
|
415
|
|
|
return $this->setModified('start_date'); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @return \DateTime|null |
420
|
|
|
* |
421
|
|
|
* @throws \Exception |
422
|
|
|
*/ |
423
|
|
|
public function getFinishDate() |
424
|
|
|
{ |
425
|
|
|
if ($this->data['finish_date']) { |
426
|
|
|
return new \DateTime($this->data['finish_date']); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
return null; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @param \DateTime $value |
434
|
|
|
* |
435
|
|
|
* @return bool |
436
|
|
|
*/ |
437
|
|
View Code Duplication |
public function setFinishDate(\DateTime $value) |
|
|
|
|
438
|
|
|
{ |
439
|
|
|
$stringValue = $value->format('Y-m-d H:i:s'); |
440
|
|
|
|
441
|
|
|
if ($this->data['finish_date'] === $stringValue) { |
442
|
|
|
return false; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
$this->data['finish_date'] = $stringValue; |
446
|
|
|
|
447
|
|
|
return $this->setModified('finish_date'); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
|
|
public function getCommitterEmail() |
454
|
|
|
{ |
455
|
|
|
return $this->data['committer_email']; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @param string|null $value |
460
|
|
|
* |
461
|
|
|
* @return bool |
462
|
|
|
* |
463
|
|
|
* @throws InvalidArgumentException |
464
|
|
|
*/ |
465
|
|
View Code Duplication |
public function setCommitterEmail($value) |
|
|
|
|
466
|
|
|
{ |
467
|
|
|
$this->validateString('committer_email', $value); |
468
|
|
|
|
469
|
|
|
if ($this->data['committer_email'] === $value) { |
470
|
|
|
return false; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
$this->data['committer_email'] = $value; |
474
|
|
|
|
475
|
|
|
return $this->setModified('committer_email'); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @return string |
480
|
|
|
*/ |
481
|
|
|
public function getCommitMessage() |
482
|
|
|
{ |
483
|
|
|
return $this->data['commit_message']; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* @param string|null $value |
488
|
|
|
* |
489
|
|
|
* @return bool |
490
|
|
|
* |
491
|
|
|
* @throws InvalidArgumentException |
492
|
|
|
*/ |
493
|
|
View Code Duplication |
public function setCommitMessage($value) |
|
|
|
|
494
|
|
|
{ |
495
|
|
|
$this->validateString('commit_message', $value); |
496
|
|
|
|
497
|
|
|
if ($this->data['commit_message'] === $value) { |
498
|
|
|
return false; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$this->data['commit_message'] = $value; |
502
|
|
|
|
503
|
|
|
return $this->setModified('commit_message'); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* @param string|null $key |
508
|
|
|
* |
509
|
|
|
* @return array|string|null |
510
|
|
|
*/ |
511
|
|
View Code Duplication |
public function getExtra($key = null) |
|
|
|
|
512
|
|
|
{ |
513
|
|
|
$data = json_decode($this->data['extra'], true); |
514
|
|
|
$extra = null; |
515
|
|
|
if (is_null($key)) { |
516
|
|
|
$extra = $data; |
517
|
|
|
} elseif (isset($data[$key])) { |
518
|
|
|
$extra = $data[$key]; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
return $extra; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @param array $value |
526
|
|
|
* |
527
|
|
|
* @return bool |
528
|
|
|
* |
529
|
|
|
* @throws InvalidArgumentException |
530
|
|
|
*/ |
531
|
|
|
public function setExtra(array $value) |
532
|
|
|
{ |
533
|
|
|
$this->validateNotNull('extra', $value); |
534
|
|
|
|
535
|
|
|
$extra = json_encode($value); |
536
|
|
|
if ($this->data['extra'] === $extra) { |
537
|
|
|
return false; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
$this->data['extra'] = $extra; |
541
|
|
|
|
542
|
|
|
return $this->setModified('extra'); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* @return string |
547
|
|
|
*/ |
548
|
|
|
public function getEnvironment() |
549
|
|
|
{ |
550
|
|
|
return $this->data['environment']; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* @param string|null $value |
555
|
|
|
* |
556
|
|
|
* @return bool |
557
|
|
|
* |
558
|
|
|
* @throws InvalidArgumentException |
559
|
|
|
*/ |
560
|
|
View Code Duplication |
public function setEnvironment($value) |
|
|
|
|
561
|
|
|
{ |
562
|
|
|
$this->validateString('environment', $value); |
563
|
|
|
|
564
|
|
|
if ($this->data['environment'] === $value) { |
565
|
|
|
return false; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$this->data['environment'] = $value; |
569
|
|
|
|
570
|
|
|
return $this->setModified('environment'); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* @return int |
575
|
|
|
*/ |
576
|
|
|
public function getSource() |
577
|
|
|
{ |
578
|
|
|
return (int)$this->data['source']; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* @param int $value |
583
|
|
|
* |
584
|
|
|
* @return bool |
585
|
|
|
* |
586
|
|
|
* @throws InvalidArgumentException |
587
|
|
|
*/ |
588
|
|
View Code Duplication |
public function setSource($value) |
|
|
|
|
589
|
|
|
{ |
590
|
|
|
$this->validateInt('source', $value); |
591
|
|
|
|
592
|
|
|
if (!in_array($value, $this->allowedSources, true)) { |
593
|
|
|
throw new InvalidArgumentException( |
594
|
|
|
'Column "source" must be one of: ' . join(', ', $this->allowedSources) . '.' |
595
|
|
|
); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
if ($this->data['source'] === $value) { |
599
|
|
|
return false; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
$this->data['source'] = $value; |
603
|
|
|
|
604
|
|
|
return $this->setModified('source'); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* @return int |
609
|
|
|
*/ |
610
|
|
|
public function getUserId() |
611
|
|
|
{ |
612
|
|
|
return (int)$this->data['user_id']; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* @param int $value |
617
|
|
|
* |
618
|
|
|
* @return bool |
619
|
|
|
* |
620
|
|
|
* @throws InvalidArgumentException |
621
|
|
|
*/ |
622
|
|
|
public function setUserId($value) |
623
|
|
|
{ |
624
|
|
|
$this->validateNotNull('user_id', $value); |
625
|
|
|
$this->validateInt('user_id', $value); |
626
|
|
|
|
627
|
|
|
if ($this->data['user_id'] === $value) { |
628
|
|
|
return false; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
$this->data['user_id'] = $value; |
632
|
|
|
|
633
|
|
|
return $this->setModified('user_id'); |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* @return int |
638
|
|
|
* |
639
|
|
|
* @throws InvalidArgumentException |
640
|
|
|
*/ |
641
|
|
|
public function getErrorsTotal() |
642
|
|
|
{ |
643
|
|
|
if (null === $this->data['errors_total'] |
644
|
|
|
&& !in_array($this->getStatus(), [self::STATUS_PENDING, self::STATUS_RUNNING], true) |
645
|
|
|
) { |
646
|
|
|
/** |
647
|
|
|
* @var BuildStore $store |
648
|
|
|
*/ |
649
|
|
|
$store = Factory::getStore('Build'); |
650
|
|
|
|
651
|
|
|
$this->setErrorsTotal($store->getErrorsCount($this->getId())); |
652
|
|
|
$store->save($this); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
return $this->data['errors_total']; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* @param int $value |
660
|
|
|
* |
661
|
|
|
* @return bool |
662
|
|
|
* |
663
|
|
|
* @throws InvalidArgumentException |
664
|
|
|
*/ |
665
|
|
|
public function setErrorsTotal($value) |
666
|
|
|
{ |
667
|
|
|
$this->validateNotNull('errors_total', $value); |
668
|
|
|
$this->validateInt('errors_total', $value); |
669
|
|
|
|
670
|
|
|
if ($this->data['errors_total'] === $value) { |
671
|
|
|
return false; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
$this->data['errors_total'] = $value; |
675
|
|
|
|
676
|
|
|
return $this->setModified('errors_total'); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* @return int|null |
681
|
|
|
* |
682
|
|
|
* @throws \Exception |
683
|
|
|
*/ |
684
|
|
|
public function getErrorsTotalPrevious() |
685
|
|
|
{ |
686
|
|
|
if (null === $this->data['errors_total_previous']) { |
687
|
|
|
/** |
688
|
|
|
* @var BuildStore $store |
689
|
|
|
*/ |
690
|
|
|
$store = Factory::getStore('Build'); |
691
|
|
|
|
692
|
|
|
$trend = $store->getBuildErrorsTrend($this->getId(), $this->getProjectId(), $this->getBranch()); |
693
|
|
|
|
694
|
|
View Code Duplication |
if (isset($trend[1])) { |
|
|
|
|
695
|
|
|
$previousBuild = $store->getById($trend[1]['build_id']); |
696
|
|
|
if ($previousBuild |
697
|
|
|
&& !in_array( |
698
|
|
|
$previousBuild->getStatus(), |
699
|
|
|
[self::STATUS_PENDING, self::STATUS_RUNNING], |
700
|
|
|
true |
701
|
|
|
) |
702
|
|
|
) { |
703
|
|
|
$this->setErrorsTotalPrevious((int)$trend[1]['count']); |
704
|
|
|
$store->save($this); |
705
|
|
|
} |
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
return $this->data['errors_total_previous']; |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* @param int $value |
714
|
|
|
* |
715
|
|
|
* @return bool |
716
|
|
|
* |
717
|
|
|
* @throws InvalidArgumentException |
718
|
|
|
*/ |
719
|
|
|
public function setErrorsTotalPrevious($value) |
720
|
|
|
{ |
721
|
|
|
$this->validateNotNull('errors_total_previous', $value); |
722
|
|
|
$this->validateInt('errors_total_previous', $value); |
723
|
|
|
|
724
|
|
|
if ($this->data['errors_total_previous'] === $value) { |
725
|
|
|
return false; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
$this->data['errors_total_previous'] = $value; |
729
|
|
|
|
730
|
|
|
return $this->setModified('errors_total_previous'); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* @return int |
735
|
|
|
* |
736
|
|
|
* @throws InvalidArgumentException |
737
|
|
|
*/ |
738
|
|
|
public function getErrorsNew() |
739
|
|
|
{ |
740
|
|
|
if (null === $this->data['errors_new']) { |
741
|
|
|
/** |
742
|
|
|
* @var BuildStore $errorStore |
743
|
|
|
*/ |
744
|
|
|
$store = Factory::getStore('Build'); |
745
|
|
|
|
746
|
|
|
$this->setErrorsNew( |
747
|
|
|
(int)$store->getNewErrorsCount($this->getId()) |
748
|
|
|
); |
749
|
|
|
|
750
|
|
|
$store->save($this); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
return $this->data['errors_new']; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* @param int $value |
758
|
|
|
* |
759
|
|
|
* @return bool |
760
|
|
|
* |
761
|
|
|
* @throws InvalidArgumentException |
762
|
|
|
*/ |
763
|
|
|
public function setErrorsNew($value) |
764
|
|
|
{ |
765
|
|
|
$this->validateNotNull('errors_new', $value); |
766
|
|
|
$this->validateInt('errors_new', $value); |
767
|
|
|
|
768
|
|
|
if ($this->data['errors_new'] === $value) { |
769
|
|
|
return false; |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
$this->data['errors_new'] = $value; |
773
|
|
|
|
774
|
|
|
return $this->setModified('errors_new'); |
775
|
|
|
} |
776
|
|
|
} |
777
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.