-
Notifications
You must be signed in to change notification settings - Fork 549
/
branches.inc
443 lines (371 loc) · 13.3 KB
/
branches.inc
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<?php
include_once __DIR__ . '/releases.inc';
include_once __DIR__ . '/version.inc';
/* Branch overrides. For situations where we've changed the exact dates for a
* branch's active support and security fix EOLs, these can be reflected here.
*
* Supported keys are:
* - stable: the end of active support (usually two years after release).
* - security: the end of security support (usually release + 3 years).
*/
$BRANCHES = [
/* 3.0 is here because version_compare() can't handle the only version in
* $OLDRELEASES, and it saves another special case in
* get_branch_security_eol_date(). */
'3.0' => [
'security' => '2000-10-20',
],
'5.3' => [
'stable' => '2013-07-11',
'security' => '2014-08-14',
],
'5.4' => [
'stable' => '2014-09-14',
'security' => '2015-09-03',
],
'5.5' => [
'stable' => '2015-07-10',
'security' => '2016-07-21',
],
'5.6' => [
'stable' => '2017-01-19',
'security' => '2018-12-31',
],
'7.0' => [
'stable' => '2018-01-04',
'security' => '2019-01-10',
],
'8.4' => [
'date' => '2024-11-21',
],
];
/* Time to keep EOLed branches in the array returned by get_active_branches(),
* which is used on the front page download links and the supported versions
* page. (Currently 28 days.) */
$KEEP_EOL = new DateInterval('P28D');
function format_interval($from, DateTime $to) {
try {
$from_obj = $from instanceof DateTime ? $from : new DateTime($from);
$diff = $to->diff($from_obj);
$times = [];
if ($diff->y) {
$times[] = [$diff->y, 'year'];
if ($diff->m) {
$times[] = [$diff->m, 'month'];
}
} elseif ($diff->m) {
$times[] = [$diff->m, 'month'];
} elseif ($diff->d) {
$times[] = [$diff->d, 'day'];
} else {
$eolPeriod = 'midnight';
}
if ($times) {
$eolPeriod = implode(', ',
array_map(
function ($t) {
return "$t[0] $t[1]" .
($t[0] != 1 ? 's' : '');
},
$times,
),
);
if ($diff->invert) {
$eolPeriod = "$eolPeriod ago";
} else {
$eolPeriod = "in $eolPeriod";
}
}
} catch (Exception $e) {
$eolPeriod = 'unknown';
}
return $eolPeriod;
}
function version_number_to_branch(string $version): ?string {
$parts = explode('.', $version);
if (count($parts) > 1) {
return "$parts[0].$parts[1]";
}
return null;
}
function get_all_branches() {
$branches = [];
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
$branch = version_number_to_branch($version);
if ($branch) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
}
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
$branch = version_number_to_branch($version);
if ($branch) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
}
krsort($branches);
foreach ($branches as &$branch) {
krsort($branch);
}
return $branches;
}
function get_active_branches($include_recent_eols = true) {
$branches = [];
$now = new DateTime();
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
$branch = version_number_to_branch($version);
if ($branch) {
$threshold = get_branch_security_eol_date($branch);
if ($threshold === null) {
// No EOL date available, assume it is ancient.
continue;
}
if ($include_recent_eols) {
$threshold->add($GLOBALS['KEEP_EOL']);
}
if ($now < $threshold) {
$branches[$major][$branch] = $release;
$branches[$major][$branch]['version'] = $version;
}
}
}
if (!empty($branches[$major])) {
ksort($branches[$major]);
}
}
ksort($branches);
return $branches;
}
/* If you provide an array to $always_include, note that the version numbers
* must be in $RELEASES _and_ must be the full version number, not the branch:
* ie provide array('5.3.29'), not array('5.3'). */
function get_eol_branches($always_include = null) {
$always_include = $always_include ?: [];
$branches = [];
$now = new DateTime();
// Gather the last release on each branch into a convenient array.
foreach ($GLOBALS['OLDRELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
$branch = version_number_to_branch($version);
if ($branch) {
if (!isset($branches[$major][$branch]) || version_compare($version, $branches[$major][$branch]['version'], 'gt')) {
$branches[$major][$branch] = [
'date' => strtotime($release['date']),
'link' => "/releases#$version",
'version' => $version,
];
}
}
}
}
/* Exclude releases from active branches, where active is defined as "in
* the $RELEASES array and not explicitly marked as EOL there". */
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
$branch = version_number_to_branch($version);
if ($branch) {
if ($now < get_branch_security_eol_date($branch)) {
/* This branch isn't EOL: remove it from our array. */
if (isset($branches[$major][$branch])) {
unset($branches[$major][$branch]);
}
} else {
/* Add the release information to the EOL branches array, since it
* should be newer than the information we got from $OLDRELEASES. */
$always_include[] = $version;
}
}
}
}
// Include any release in the always_include list that's in $RELEASES.
if ($always_include) {
foreach ($always_include as $version) {
$parts = explode('.', $version);
$major = $parts[0];
if (isset($GLOBALS['RELEASES'][$major][$version])) {
$release = $GLOBALS['RELEASES'][$major][$version];
$branch = version_number_to_branch($version);
if ($branch) {
$branches[$major][$branch] = [
'date' => strtotime($release['source'][0]['date']),
'link' => "/downloads#v$version",
'version' => $version,
];
}
}
}
}
krsort($branches);
foreach ($branches as &$branch) {
krsort($branch);
}
return $branches;
}
/* $branch is expected to have at least two components: MAJOR.MINOR or
* MAJOR.MINOR.REVISION (the REVISION will be ignored if provided). This will
* return either null (if no release exists on the given branch), or the usual
* version metadata from $RELEASES for a single release. */
function get_initial_release($branch) {
$branch = version_number_to_branch($branch);
if (!$branch) {
return null;
}
$major = substr($branch, 0, strpos($branch, '.'));
if (isset($GLOBALS['OLDRELEASES'][$major]["$branch.0"])) {
return $GLOBALS['OLDRELEASES'][$major]["$branch.0"];
}
if(isset($GLOBALS['BRANCHES'][$branch])) {
return $GLOBALS['BRANCHES'][$branch];
}
/* If there's only been one release on the branch, it won't be in
* $OLDRELEASES yet, so let's check $RELEASES. */
if (isset($GLOBALS['RELEASES'][$major]["$branch.0"])) {
// Fake a date like we have on the oldreleases array.
$release = $GLOBALS['RELEASES'][$major]["$branch.0"];
$release['date'] = $release['source'][0]['date'];
return $release;
}
// Shrug.
return null;
}
function get_final_release($branch) {
$branch = version_number_to_branch($branch);
if (!$branch) {
return null;
}
$major = substr($branch, 0, strpos($branch, '.'));
$last = "$branch.0";
foreach ($GLOBALS['OLDRELEASES'][$major] as $version => $release) {
if (version_number_to_branch($version) == $branch && version_compare($version, $last, '>')) {
$last = $version;
}
}
if (isset($GLOBALS['OLDRELEASES'][$major][$last])) {
return $GLOBALS['OLDRELEASES'][$major][$last];
}
/* If there's only been one release on the branch, it won't be in
* $OLDRELEASES yet, so let's check $RELEASES. */
if (isset($GLOBALS['RELEASES'][$major][$last])) {
// Fake a date like we have on the oldreleases array.
$release = $GLOBALS['RELEASES'][$major][$last];
$release['date'] = $release['source'][0]['date'];
return $release;
}
// Shrug.
return null;
}
function get_branch_bug_eol_date($branch): ?DateTime
{
if (isset($GLOBALS['BRANCHES'][$branch]['stable'])) {
return new DateTime($GLOBALS['BRANCHES'][$branch]['stable']);
}
$date = get_branch_release_date($branch);
$date = $date?->add(new DateInterval('P2Y'));
// Versions before 8.2 do not extend the release cycle to the end of the year
if (version_compare($branch, '8.2', '<')) {
return $date;
}
// Extend the release cycle to the end of the year
return $date?->setDate($date->format('Y'), 12, 31);
}
function get_branch_security_eol_date($branch): ?DateTime
{
if (isset($GLOBALS['BRANCHES'][$branch]['security'])) {
return new DateTime($GLOBALS['BRANCHES'][$branch]['security']);
}
/* Versions before 5.3 are based solely on the final release date in
* $OLDRELEASES. */
if (version_compare($branch, '5.3', '<')) {
$release = get_final_release($branch);
return $release ? new DateTime($release['date']) : null;
}
$date = get_branch_release_date($branch);
// Versions before 8.1 have 3-year support since the initial release
if (version_compare($branch, '8.1', '<')) {
return $date?->add(new DateInterval('P3Y'));
}
$date = $date?->add(new DateInterval('P4Y'));
// Extend the release cycle to the end of the year
return $date?->setDate($date->format('Y'), 12, 31);
}
function get_branch_release_date($branch): ?DateTime
{
$initial = get_initial_release($branch);
return $initial ? new DateTime($initial['date']) : null;
}
function get_branch_support_state($branch) {
$initial = get_branch_release_date($branch);
$bug = get_branch_bug_eol_date($branch);
$security = get_branch_security_eol_date($branch);
if ($initial && $bug && $security) {
$now = new DateTime();
if ($now >= $security) {
return 'eol';
}
if ($now >= $bug) {
return 'security';
}
if ($now >= $initial) {
return 'stable';
}
return 'future';
}
return null;
}
function compare_version(array $arrayA, string $versionB)
{
$arrayB = version_array($versionB, count($arrayA));
foreach ($arrayA as $index => $componentA) {
$componentA = $arrayA[$index];
$componentB = $arrayB[$index];
if ($componentA != $componentB) {
return $componentA > $componentB ? 1 : -1;
}
}
return 0;
}
function version_array(string $version, ?int $length = null)
{
$versionArray = array_map(
'intval',
explode('.', $version),
);
if (is_int($length)) {
$versionArray = count($versionArray) < $length
? array_pad($versionArray, $length, 0)
: array_slice(
$versionArray,
0,
$length,
);
}
return $versionArray;
}
function get_current_release_for_branch(int $major, ?int $minor): ?string {
global $RELEASES, $OLDRELEASES;
$prefix = "{$major}.";
if ($minor !== null) {
$prefix .= "{$minor}.";
}
foreach (($RELEASES[$major] ?? []) as $version => $_) {
if (!strncmp($prefix, $version, strlen($prefix))) {
return $version;
}
}
foreach (($OLDRELEASES[$major] ?? []) as $version => $_) {
if (!strncmp($prefix, $version, strlen($prefix))) {
return $version;
}
}
return null;
}