-
Notifications
You must be signed in to change notification settings - Fork 691
Expand file tree
/
Copy pathUpdate.php
More file actions
136 lines (117 loc) Β· 3.26 KB
/
Update.php
File metadata and controls
136 lines (117 loc) Β· 3.26 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\models;
use craft\base\Model;
/**
* Craft/plugin update model.
*
* @property bool $hasCritical Whether any of the updates have a critical release available
* @property bool $hasReleases Whether there are any releases available
* @property UpdateRelease|null $latest The latest release (if any are available)
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0.0
*/
class Update extends Model
{
public const STATUS_ELIGIBLE = 'eligible';
public const STATUS_BREAKPOINT = 'breakpoint';
public const STATUS_EXPIRED = 'expired';
/**
* @var string The status of the update (eligible, breakpoint, or expired)
* @phpstan-var self::STATUS_ELIGIBLE|self::STATUS_BREAKPOINT|self::STATUS_EXPIRED
*/
public string $status = self::STATUS_ELIGIBLE;
/**
* @var float|null The price to renew the license, if expired
*/
public ?float $renewalPrice = null;
/**
* @var string|null The renewal price's currency
*/
public ?string $renewalCurrency = null;
/**
* @var string|null The URL that the Renew button should link to
*/
public ?string $renewalUrl = null;
/**
* @var UpdateRelease[] The available releases
*/
public array $releases = [];
/**
* @var string|null The PHP version constraint required by this version
* @since 3.5.15
*/
public ?string $phpConstraint = null;
/**
* @var string The package name that should be used when updating
*/
public string $packageName;
/**
* @var bool Whether the package is abandoned
* @since 3.6.7
*/
public bool $abandoned = false;
/**
* @var string|null The name of the suggested replacement package
* @since 3.6.7
*/
public ?string $replacementName = null;
/**
* @var string|null The handle of the suggested replacement package
* @since 3.6.7
*/
public ?string $replacementHandle = null;
/**
* @var string|null The URL of the suggested replacement package
* @since 3.6.7
*/
public ?string $replacementUrl = null;
/**
* @inheritdoc
*/
public function init(): void
{
parent::init();
foreach ($this->releases as $key => $release) {
if (!$release instanceof UpdateRelease) {
$this->releases[$key] = new UpdateRelease($release);
}
}
}
/**
* Returns whether there are any releases available.
*
* @return bool
*/
public function getHasReleases(): bool
{
return !empty($this->releases);
}
/**
* Returns whether there are any critical releases available.
*
* @return bool
*/
public function getHasCritical(): bool
{
foreach ($this->releases as $release) {
if ($release->isCritical($this)) {
return true;
}
}
return false;
}
/**
* Returns the latest release (if any are available).
*
* @return UpdateRelease|null
*/
public function getLatest(): ?UpdateRelease
{
return $this->releases[0] ?? null;
}
}