|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Frosh\Tools\Controller; |
| 4 | + |
| 5 | +use Shopware\Core\Framework\Routing\Annotation\RouteScope; |
| 6 | +use Shopware\Core\Kernel; |
| 7 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 8 | +use Symfony\Component\Routing\Annotation\Route; |
| 9 | + |
| 10 | +/** |
| 11 | + * @RouteScope(scopes={"api"}) |
| 12 | + * @Route(path="/api/_action/frosh-tools") |
| 13 | + */ |
| 14 | +class ShopwareFilesController |
| 15 | +{ |
| 16 | + private string $shopwareVersion; |
| 17 | + |
| 18 | + private string $projectDir; |
| 19 | + |
| 20 | + public function __construct(string $shopwareVersion, string $projectDir) |
| 21 | + { |
| 22 | + $this->shopwareVersion = $shopwareVersion; |
| 23 | + $this->projectDir = $projectDir; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @Route(path="/shopware-files", methods={"GET"}, name="api.frosh.tools.shopware-files") |
| 28 | + */ |
| 29 | + public function listShopwareFiles(): JsonResponse |
| 30 | + { |
| 31 | + if ($this->shopwareVersion === Kernel::SHOPWARE_FALLBACK_VERSION) { |
| 32 | + return new JsonResponse(['error' => 'Git version is not supported']); |
| 33 | + } |
| 34 | + |
| 35 | + if (!file_exists($this->projectDir . '/vendor/shopware/core')) { |
| 36 | + return new JsonResponse(['error' => 'Works only in Production template']); |
| 37 | + } |
| 38 | + |
| 39 | + $url = sprintf('https://swagger.docs.fos.gg/version/%s/Files.md5sums', $this->shopwareVersion); |
| 40 | + |
| 41 | + $data = trim(@file_get_contents($url)); |
| 42 | + |
| 43 | + if (empty($data)) { |
| 44 | + return new JsonResponse(['error' => 'No file information for this Shopware version']); |
| 45 | + } |
| 46 | + |
| 47 | + $invalidFiles = []; |
| 48 | + |
| 49 | + foreach (explode("\n", $data) as $row) { |
| 50 | + [$expectedMd5Sum, $file] = explode(' ', trim($row)); |
| 51 | + $fileAvailable = is_file($this->projectDir . $file); |
| 52 | + |
| 53 | + if ($fileAvailable) { |
| 54 | + $md5Sum = md5_file($this->projectDir . $file); |
| 55 | + |
| 56 | + // This file differs on update systems. This change is missing in update packages lol! |
| 57 | + // @see: https://github.com/shopware/platform/commit/957e605c96feef67a6c759f00c58e35d2d1ac84f#diff-e49288a50f0d7d8acdabb5ffef2edcd5ac4f4126f764d3153d19913ce98aba1cL10-R80 |
| 58 | + // @see: https://issues.shopware.com/issues/NEXT-11618 |
| 59 | + if ($file === 'vendor/shopware/core/Checkout/Order/Aggregate/OrderAddress/OrderAddressDefinition.php' && $md5Sum === 'e3da59baff091fd044a12a61cd445385') { |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + // This file differs on update systems. This change is missing in update packages lol! |
| 64 | + // @see: https://github.com/shopware/platform/commit/bbdcbe254e3239e92eb1f71a7afedfb94b7fb150 |
| 65 | + // @see: https://issues.shopware.com/issues/NEXT-11775 |
| 66 | + if ($file === 'vendor/shopware/administration/Resources/app/administration/src/app/component/media/sw-media-compact-upload-v2/index.js' && $md5Sum === '74d18e580ffe87559e6501627090efb3') { |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + if ($md5Sum !== $expectedMd5Sum) { |
| 71 | + $invalidFiles[] = ['name' => $file]; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + return new JsonResponse(['ok' => empty($invalidFiles), 'files' => $invalidFiles]); |
| 77 | + } |
| 78 | +} |
0 commit comments