-
Notifications
You must be signed in to change notification settings - Fork 691
Expand file tree
/
Copy pathUpdateRelease.php
More file actions
93 lines (80 loc) Β· 2.02 KB
/
UpdateRelease.php
File metadata and controls
93 lines (80 loc) Β· 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\models;
use craft\base\Model;
use craft\events\UpdateReleaseEvent;
use craft\helpers\DateTimeHelper;
use DateTime;
use DateTimeZone;
/**
* Stores the info for an update release.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
class UpdateRelease extends Model
{
/**
* @event UpdateReleaseEvent The event that is triggered when determining if this release should be flagged as critical.
* @see isCritical()
* @since 5.7.0
*/
public const EVENT_IS_CRITICAL = 'isCritical';
/**
* @var string Version
*/
public string $version;
/**
* @var DateTime|null Date
*/
public ?DateTime $date = null;
/**
* @var bool Critical
*/
public bool $critical = false;
/**
* @var string|null Notes
*/
public ?string $notes = null;
/**
* @inheritdoc
*/
public function fields(): array
{
$fields = parent::fields();
// Don't include time zone in the date
$fields['date'] = function(): ?string {
if (isset($this->date)) {
return DateTimeHelper::toDateTime($this->date)->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d\TH:i:s');
}
return null;
};
return $fields;
}
/**
* Returns whether the release should be flagged as critical.
*
* @return bool
* @since 5.7.0
*/
public function isCritical(Update $update): bool
{
if (!$this->critical) {
return false;
}
if ($this->hasEventHandlers(self::EVENT_IS_CRITICAL)) {
$event = new UpdateReleaseEvent([
'update' => $update,
]);
$this->trigger(self::EVENT_IS_CRITICAL, $event);
if ($event->handled) {
return false;
}
}
return true;
}
}