-
Notifications
You must be signed in to change notification settings - Fork 15
/
matomo_version_parser.php
100 lines (83 loc) · 3.3 KB
/
matomo_version_parser.php
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
// tiny script to get plugin version from plugin.json from a bash script
require_once __DIR__ . '/../../core/Version.php';
function getRequiredMatomoVersions($pluginJsonContents, $returnAlsoInvalid = false)
{
$requiredMatomoVersion = '';
if (isset($pluginJsonContents["require"]["piwik"])) {
$requiredMatomoVersion = (string) $pluginJsonContents["require"]["piwik"];
} else if (isset($pluginJsonContents["require"]["matomo"])) {
$requiredMatomoVersion = (string) $pluginJsonContents["require"]["matomo"];
}
$requiredVersions = explode(',', $requiredMatomoVersion);
$versions = array();
foreach ($requiredVersions as $required) {
if (preg_match('{^(<>|!=|>=?|<=?|==?)\s*(.*)}', $required, $matches)) {
$comparison = trim($matches[1]);
$version = $matches[2];
if (!preg_match("/^[^0-9]*(.*)/", $version) || empty($version)) {
// not a valid version number
continue;
}
if (!$returnAlsoInvalid && version_compare($version, \Piwik\Version::VERSION) > 0) {
continue;
}
$versions[] = array(
'comparison' => $comparison,
'version' => $version
);
}
}
return $versions;
}
function getMinVersion(array $requiredVersions)
{
$minVersion = '';
foreach ($requiredVersions as $required) {
$comparison = $required['comparison'];
$version = $required['version'];
if (in_array($comparison, array('>=','>', '=='))) {
if (empty($minVersion)) {
$minVersion = $version;
} elseif (version_compare($version, $minVersion, '<=')) {
$minVersion = $version;
}
}
}
return $minVersion;
}
function getMaxVersion(array $requiredVersions)
{
$maxVersion = '';
foreach ($requiredVersions as $required) {
$comparison = $required['comparison'];
$version = $required['version'];
if ($comparison == '<' && $version == '3.0.0-b1') {
$maxVersion = trim(file_get_contents('https://api.matomo.org/1.0/getLatestVersion/?release_channel=latest_2x_beta'));
continue;
} elseif ($comparison == '<' && $version == '4.0.0-b1') {
$maxVersion = trim(file_get_contents('https://api.matomo.org/1.0/getLatestVersion/?release_channel=latest_3x_beta'));
continue;
} elseif ($comparison == '<' && $version == '5.0.0-b1') {
$maxVersion = trim(file_get_contents('https://api.matomo.org/1.0/getLatestVersion/?release_channel=latest_4x_beta'));
continue;
} elseif ($comparison == '<' && $version == '6.0.0-b1') {
$maxVersion = trim(file_get_contents('https://api.matomo.org/1.0/getLatestVersion/?release_channel=latest_5x_beta'));
continue;
}
if (in_array($comparison, array('<', '<=', '=='))) {
if (empty($maxVersion)) {
$maxVersion = $version;
} elseif (version_compare($version, $maxVersion, '>=')) {
$maxVersion = $version;
}
}
}
return $maxVersion;
}