Skip to content

Commit 787df37

Browse files
committed
fix(data): load plugin data
1 parent b39972d commit 787df37

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

src/Action/LoadPluginAction.php

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function execute(string|PackageIndexEntry $packageInformation, \DateTimeI
4141
$packageInformation = $this->indexFileService->getPackageInformation($packageInformation);
4242
}
4343

44-
if (null === $packageInformation) {
44+
if (is_null($packageInformation)) {
4545
return;
4646
}
4747

@@ -52,26 +52,17 @@ public function execute(string|PackageIndexEntry $packageInformation, \DateTimeI
5252

5353
$version = $this->findSuitableVersion($packagistData);
5454

55-
if (null === $version) {
55+
if (is_null($version)) {
5656
return;
5757
}
5858

5959
$githubUrl = \str_replace('.git', '', $version['source']['url']);
6060
$githubUrl = \str_replace('https://github.com/', 'https://raw.githubusercontent.com/', $githubUrl.'/refs/heads/main/');
6161
$mainExtensionYmlUrl = $githubUrl.'.shopware-extension.yml';
6262

63-
$extensionYmlUrl = null;
64-
65-
$isComposer = false;
66-
67-
$mainExtensionYmlResponse = $this->httpClient->request('GET', $mainExtensionYmlUrl);
68-
if (200 === $mainExtensionYmlResponse->getStatusCode()) {
69-
$extensionYmlUrl = $mainExtensionYmlUrl;
70-
} else {
71-
$isComposer = true;
72-
}
73-
7463
$pluginData = [
64+
'icon' => $version['extra']['plugin-icon'] ?? $githubUrl . '/src/Resources/config/plugin.png',
65+
...$packageInformation->additionalMetadataExists ? $this->fetchExtensionYmlData($mainExtensionYmlUrl, $githubUrl): [],
7566
'packageName' => $packageInformation->packageName,
7667
'manufacturer' => implode(', ', array_column($version['authors'], 'name')),
7768
'manufacturerLink' => array_values($version['extra']['manufacturerLink'] ?? ['https://github.com'])[0], // get first translation - TODO: fix
@@ -84,38 +75,11 @@ public function execute(string|PackageIndexEntry $packageInformation, \DateTimeI
8475
$pluginData['manufacturer'] = 'UNKNOWN';
8576
}
8677

87-
if (!$isComposer) {
88-
$extensionYmlResponse = $this->httpClient->request('GET', $extensionYmlUrl);
89-
if (200 === $extensionYmlResponse->getStatusCode()) {
90-
$extensionYmlData = Yaml::parse($extensionYmlResponse->getContent());
91-
if (isset($extensionYmlData['store'])) {
92-
if (isset($extensionYmlData['store']['icon'])) {
93-
$pluginData['icon'] = $githubUrl.'/'.$extensionYmlData['store']['icon'];
94-
} else {
95-
$pluginData['icon'] = $githubUrl.'/src/Resources/config/plugin.png';
96-
}
97-
foreach ($extensionYmlData['store']['images'] as $images) {
98-
$pluginData['images'][] = $githubUrl.'/'.$images['file'];
99-
}
100-
if (isset($extensionYmlData['store']['description']['en'])) {
101-
$pluginData['description']['en-GB'] = $extensionYmlData['store']['description']['en'];
102-
}
103-
if (isset($extensionYmlData['store']['description']['de'])) {
104-
$pluginData['description']['de-DE'] = $extensionYmlData['store']['description']['de'];
105-
}
106-
107-
// TODO Load from markdown files
108-
109-
// TODO load images from folder
110-
} else {
111-
$pluginData['icon'] = $githubUrl.'/src/Resources/config/plugin.png';
112-
$isComposer = true;
113-
}
114-
}
78+
if (!isset($pluginData['description']['en-GB'])) {
79+
$pluginData['description']['en-GB'] = $version['extra']['description']['en-GB'] ?? $packageInformation->packageName;
11580
}
11681

117-
if ($isComposer) {
118-
$pluginData['description']['en-GB'] = $version['extra']['description']['en-GB'] ?? $packageInformation->packageName;
82+
if (!isset($pluginData['description']['de-DE'])) {
11983
$pluginData['description']['de-DE'] = $version['extra']['description']['de-DE'] ?? $packageInformation->packageName;
12084
}
12185

@@ -147,6 +111,38 @@ public function execute(string|PackageIndexEntry $packageInformation, \DateTimeI
147111
$this->availableOpensourcePluginRepository->upsert([$pluginData], Context::createDefaultContext());
148112
}
149113

114+
private function fetchExtensionYmlData(string $mainExtensionYmlUrl, string $githubUrl): array
115+
{
116+
$extensionYmlResponse = $this->httpClient->request('GET', $mainExtensionYmlUrl);
117+
if (200 !== $extensionYmlResponse->getStatusCode()) {
118+
return [];
119+
}
120+
121+
$extensionYmlData = Yaml::parse($extensionYmlResponse->getContent());
122+
123+
$pluginData = [];
124+
if (isset($extensionYmlData['store'])) {
125+
if (isset($extensionYmlData['store']['icon'])) {
126+
$pluginData['icon'] = $githubUrl . '/' . $extensionYmlData['store']['icon'];
127+
}
128+
foreach ($extensionYmlData['store']['images'] as $images) {
129+
$pluginData['images'][] = $githubUrl . '/' . $images['file'];
130+
}
131+
if (isset($extensionYmlData['store']['description']['en'])) {
132+
$pluginData['description']['en-GB'] = $extensionYmlData['store']['description']['en'];
133+
}
134+
if (isset($extensionYmlData['store']['description']['de'])) {
135+
$pluginData['description']['de-DE'] = $extensionYmlData['store']['description']['de'];
136+
}
137+
138+
// TODO Load from markdown files
139+
140+
// TODO load images from folder
141+
}
142+
143+
return $pluginData;
144+
}
145+
150146
private function findSuitableVersion(array $packagistData): ?array
151147
{
152148
$versions = $packagistData['package']['versions'];

src/Service/IndexFileService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private function loadPluginInformationFromFile(): void
9393
packageName: $package,
9494
repositoryUrl: $packageInfo['repositoryUrl'],
9595
ref: $packageInfo['ref'],
96+
additionalMetadataExists: $packageInfo['additionalMetadataExists'] ?? false,
9697
latestCommitTime: new \DateTime('@'.$packageInfo['latestCommitTime']),
9798
);
9899
}

src/Struct/PackageIndexEntry.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function __construct(
1212
public string $packageName,
1313
public string $repositoryUrl,
1414
public string $ref,
15+
public bool $additionalMetadataExists,
1516
public \DateTimeInterface $latestCommitTime,
1617
) {
1718
}

0 commit comments

Comments
 (0)