Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Controller/ShopwareFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function listShopwareFiles(): JsonResponse

$invalidFiles = [];
$allFilesAreOkay = true;
$shopwarePatches = $this->getShopwarePatches();

foreach (explode("\n", $data) as $row) {
if ($this->isPlatform) {
Expand All @@ -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,
];
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
</template>

<template #column-expected="{ item }">
<span v-if="item.expected">{{ $tc('frosh-tools.tabs.files.expectedProject') }}</span>
<span v-if="item.patched">{{ $tc('frosh-tools.tabs.files.expectedPatched') }}</span>
<span v-else-if="item.expected">{{ $tc('frosh-tools.tabs.files.expectedProject') }}</span>
<span v-else>{{ $tc('frosh-tools.tabs.files.expectedAll') }}</span>
<sw-help-text
style="margin-left: 8px"
v-if="item.patched"
:text="item.patched">
</sw-help-text>
</template>

<template #actions="{ item }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"restoreFile": "Datei wiederherstellen"
},
"expectedAll": "Datei wurde manipuliert",
"expectedPatched": "Datei wurde gepatcht, Fehler wird ignoriert durch Projekt Konfiguration",
"expectedProject": "Datei wurde manipuliert, Fehler wird ignoriert durch Projekt Konfiguration"
},
"state-machines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"restoreFile": "Restore file"
},
"expectedAll": "File has been modified",
"expectedPatched": "File has been patched and will be ignored by project settings",
"expectedProject": "File has been modified, but will be ignored by project settings"
},
"state-machines": {
Expand Down