-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-m1-patches.php
58 lines (46 loc) · 1.34 KB
/
get-m1-patches.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
<?php
$configFile = isset($argv[1]) ? $argv[1] : '';
if (!$configFile) {
error('Config file is required as first parameter.');
}
$magentoVersion = isset($argv[2]) ? $argv[2] : '';
if (!$magentoVersion) {
error('Magento Version is required as second parameter.');
}
$isEnterprise = versionAtLeast($magentoVersion, '1.10.0.0');
$config = getConfigData($configFile);
$patches = [];
foreach ($config as $patch => $fixedVersions) {
$compareWith = $isEnterprise ? $fixedVersions['enterprise'] : $fixedVersions['community'];
if (!versionAtLeast($magentoVersion, $compareWith)) {
$patches[] = $patch;
}
}
print implode(',', $patches);
function versionAtLeast($versionToCheck, $requiredVersion)
{
return version_compare($versionToCheck, $requiredVersion) >= 0;
}
function error($message)
{
print $message . PHP_EOL;
exit(1);
}
function getConfigData($configFile)
{
if (!file_exists($configFile)) {
error('Config file is required as parameter.');
}
if (!is_readable($configFile)) {
error('Config file is not readable.');
}
$config = file_get_contents($configFile);
if (!$config) {
error('Config file is empty');
}
$parsedConfig = json_decode($config, true);
if (is_null($parsedConfig)) {
error('Cannot parse JSON in config file');
}
return $parsedConfig;
}