-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile-checker.php
77 lines (60 loc) · 2.8 KB
/
file-checker.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
<?php
$hashType = version_compare(\PHP_VERSION, '8.1.0', '>=') ? 'xxh64' : 'md5';
$installedVersion = getUsedShopwareVersion();
echo '=> Detected Shopware Version: ' . $installedVersion . PHP_EOL;
$md5Sums = getMd5SumsForVersion($installedVersion);
$baseDir = __DIR__ . '/';
$foundSomething = false;
foreach ($md5Sums as $row) {
list($expectedMd5Sum, $file) = explode(' ', trim($row));
$fileAvailable = is_file($baseDir . $file);
if ($fileAvailable) {
$md5Sum = hash_file($hashType, $baseDir . $file);
// This file differs on update systems. This change is missing in update packages lol!
// @see: https://github.com/shopware/platform/commit/957e605c96feef67a6c759f00c58e35d2d1ac84f#diff-e49288a50f0d7d8acdabb5ffef2edcd5ac4f4126f764d3153d19913ce98aba1cL10-R80
// @see: https://issues.shopware.com/issues/NEXT-11618
if ($file === 'vendor/shopware/core/Checkout/Order/Aggregate/OrderAddress/OrderAddressDefinition.php' && $md5Sum === 'e3da59baff091fd044a12a61cd445385') {
continue;
}
// This file differs on update systems. This change is missing in update packages lol!
// @see: https://github.com/shopware/platform/commit/bbdcbe254e3239e92eb1f71a7afedfb94b7fb150
// @see: https://issues.shopware.com/issues/NEXT-11775
if ($file === 'vendor/shopware/administration/Resources/app/administration/src/app/component/media/sw-media-compact-upload-v2/index.js' && $md5Sum === '74d18e580ffe87559e6501627090efb3') {
continue;
}
if ($md5Sum !== $expectedMd5Sum) {
echo(sprintf('File "%s" has been modified. Please revert it back to default!' . PHP_EOL, $file));
$foundSomething = true;
}
} else {
echo(sprintf('File "%s" is missing. Please get it back!' . PHP_EOL, $file));
$foundSomething = true;
}
}
if (!$foundSomething) {
echo 'Everything is okay!' . PHP_EOL;
}
function getUsedShopwareVersion(): string
{
$lock = json_decode(file_get_contents(__DIR__ . '/composer.lock'), true);
foreach ($lock['packages'] as $package) {
if ($package['name'] === 'shopware/core') {
return ltrim($package['version'], 'v');
}
}
echo('Cannot find installed Shopware Version in Composer' . PHP_EOL);
exit(1);
}
function getMd5SumsForVersion(string $version): array
{
global $hashType;
$type = $hashType === 'xxh64' ? 'xxhsums' : 'md5sums';
$url = sprintf('https://swagger.docs.fos.gg/version/%s/Files.' . $type, $version);
echo '=> Downloading meta information from ' . $url . PHP_EOL;
$data = trim(@file_get_contents($url));
if (empty($data)) {
echo(sprintf('Cannot download md5sums from %s. Maybe not generated? Contact Shyim' . PHP_EOL, $url));
exit(1);
}
return explode("\n", $data);
}