From 129232649c2b3c3aebb65f05ab43c19b3da6e94d Mon Sep 17 00:00:00 2001 From: Melvin Achterhuis Date: Sun, 2 Mar 2025 03:46:40 +0100 Subject: [PATCH] feat: file checker show if file patched through composer --- src/Controller/ShopwareFilesController.php | 53 +++++++++++++++++++ .../frosh-tools-tab-files/template.twig | 8 ++- .../src/module/frosh-tools/snippet/de-DE.json | 1 + .../src/module/frosh-tools/snippet/en-GB.json | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/Controller/ShopwareFilesController.php b/src/Controller/ShopwareFilesController.php index 960cdb6a..409b5682 100644 --- a/src/Controller/ShopwareFilesController.php +++ b/src/Controller/ShopwareFilesController.php @@ -70,6 +70,7 @@ public function listShopwareFiles(): JsonResponse $invalidFiles = []; $allFilesAreOkay = true; + $shopwarePatches = $this->getShopwarePatches(); foreach (explode("\n", $data) as $row) { if ($this->isPlatform) { @@ -96,10 +97,16 @@ public function listShopwareFiles(): JsonResponse $allFilesAreOkay = false; } + $isPatched = $shopwarePatches ? $this->isFilePatched($file, $shopwarePatches) : false; + if ($isPatched) { + $ignoredState = self::STATUS_IGNORED_IN_PROJECT; + } + $invalidFiles[] = [ 'name' => $file, 'shopwareUrl' => $this->getShopwareUrl($file), 'expected' => $ignoredState === self::STATUS_IGNORED_IN_PROJECT, + 'patched' => $isPatched, ]; } @@ -261,4 +268,50 @@ private function getNameByIntegrationId(string $integrationId): ?string return 'integration ' . $integrationEntity->getLabel(); } + + private function getShopwarePatches(): ?array + { + $shopwarePatches = []; + $composerFile = $this->projectDir . '/composer.json'; + if (!is_file($composerFile)) { + return null; + } + + $composerJson = json_decode(file_get_contents($composerFile), true); + $patchedPackages = $composerJson['extra']['patches'] ?? []; + + foreach ($patchedPackages as $packageName => $patches) { + if (!str_starts_with($packageName, 'shopware')) { + continue; + } + + foreach ($patches as $patch) { + $patchFileLocation = $this->projectDir . '/' . $patch; + if (is_file($patchFileLocation)) { + $shopwarePatches[$packageName][] = $patch; + } + } + } + + return $shopwarePatches; + } + + private function isFilePatched(string $fileName, array $shopwarePatches): ?string + { + foreach ($shopwarePatches as $package) { + foreach ($package as $patch) { + $patchFileLocation = $this->projectDir . '/' . $patch; + if (!is_file($patchFileLocation)) { + continue; + } + + $patchFile = file_get_contents($patchFileLocation); + if (str_contains($patchFile, $fileName)) { + return $patch; + } + } + } + + return null; + } } diff --git a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-files/template.twig b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-files/template.twig index 051f5a70..e6fb8540 100644 --- a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-files/template.twig +++ b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-files/template.twig @@ -28,8 +28,14 @@