Skip to content

Commit 8f90988

Browse files
committed
Add shopware file checker, fixes #23
1 parent 0ae8cf6 commit 8f90988

10 files changed

Lines changed: 170 additions & 1 deletion

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}

src/Resources/app/administration/src/api/frosh-tools.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ class FroshTools extends ApiService {
9494
return response;
9595
});
9696
}
97+
98+
getShopwareFiles() {
99+
const apiRoute = `${this.getApiBasePath()}/shopware-files`;
100+
return this.httpClient.get(
101+
apiRoute,
102+
{
103+
headers: this.getBasicHeaders()
104+
}
105+
).then((response) => {
106+
return response;
107+
});
108+
}
97109
}
98110

99111
export default FroshTools;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import template from './template.twig';
2+
3+
const { Component, Mixin } = Shopware;
4+
5+
Component.register('frosh-tools-tab-files', {
6+
template,
7+
inject: ['repositoryFactory', 'FroshToolsService'],
8+
mixins: [
9+
Mixin.getByName('notification')
10+
],
11+
12+
data() {
13+
return {
14+
items: {},
15+
isLoading: true
16+
};
17+
},
18+
19+
created() {
20+
this.createdComponent();
21+
},
22+
23+
computed: {
24+
columns() {
25+
return [
26+
{
27+
property: 'name',
28+
label: 'frosh-tools.name',
29+
rawData: true,
30+
primary: true
31+
}
32+
];
33+
}
34+
},
35+
36+
methods: {
37+
async createdComponent() {
38+
this.items = (await this.FroshToolsService.getShopwareFiles()).data;
39+
this.isLoading = false;
40+
}
41+
}
42+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<sw-card-view>
2+
<sw-card :title="$tc('frosh-tools.tabs.files.title')" :isLoading="isLoading" :large="true">
3+
<sw-alert variant="error" v-if="items.error">{{ items.error }}</sw-alert>
4+
5+
<sw-alert variant="success" v-if="items.ok">All files are not modified</sw-alert>
6+
7+
<sw-data-grid
8+
v-if="items.files"
9+
:showSelection="false"
10+
:dataSource="items.files"
11+
:columns="columns">
12+
</sw-data-grid>
13+
</sw-card>
14+
</sw-card-view>

src/Resources/app/administration/src/module/frosh-tools/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './component/frosh-tools-tab-queue';
44
import './component/frosh-tools-tab-scheduled';
55
import './component/frosh-tools-tab-elasticsearch';
66
import './component/frosh-tools-tab-logs';
7+
import './component/frosh-tools-tab-files';
78
import './page/index';
89

910
Shopware.Module.register('frosh-tools', {
@@ -62,6 +63,13 @@ Shopware.Module.register('frosh-tools', {
6263
parentPath: 'frosh.tools.index'
6364
}
6465
},
66+
files: {
67+
component: 'frosh-tools-tab-files',
68+
path: 'files',
69+
meta: {
70+
parentPath: 'frosh.tools.index'
71+
}
72+
},
6573
}
6674
},
6775
},

src/Resources/app/administration/src/module/frosh-tools/page/index/template.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
{{ $tc('frosh-tools.tabs.logs.title') }}
2727
</sw-tabs-item>
2828

29+
<sw-tabs-item :route="{ name: 'frosh.tools.index.files' }">
30+
{{ $tc('frosh-tools.tabs.files.title') }}
31+
</sw-tabs-item>
32+
2933
{# <sw-tabs-item :route="{ name: 'frosh.tools.index.elasticsearch' }">#}
3034
{# {{ $tc('frosh-tools.tabs.elasticsearch.title') }}#}
3135
{# </sw-tabs-item>#}

src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
},
2323
"logs": {
2424
"title": "Log viewer"
25+
},
26+
"files": {
27+
"title": "Shopware Dateien Checker"
2528
}
2629
},
2730
"clear": "Leeren",

src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
},
2323
"logs": {
2424
"title": "Log viewer"
25+
},
26+
"files": {
27+
"title": "Shopware file checker"
2528
}
2629
},
2730
"clear": "Clear",

src/Resources/config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,10 @@
9292
<argument>task_logging</argument>
9393
<argument>14</argument>
9494
</service>
95+
96+
<service id="Frosh\Tools\Controller\ShopwareFilesController" public="true">
97+
<argument>%kernel.shopware_version%</argument>
98+
<argument>%kernel.project_dir%</argument>
99+
</service>
95100
</services>
96101
</container>

src/Resources/public/administration/js/frosh-tools.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)