Skip to content

Commit 20025b7

Browse files
committed
feat(list): link installed plugins
implements #8
1 parent 2d1022b commit 20025b7

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/Action/LoadPluginAction.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
1616
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
1717
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
18+
use Shopware\Core\Framework\Plugin\PluginCollection;
1819
use Shopware\Core\Framework\Uuid\Uuid;
1920
use Shopware\Core\System\Language\LanguageCollection;
2021
use Symfony\Component\Yaml\Yaml;
@@ -28,11 +29,11 @@
2829

2930
readonly class LoadPluginAction
3031
{
31-
3232
/**
3333
* @param EntityRepository<AvailableOpensourcePluginCollection> $availableOpensourcePluginRepository
34-
* @param EntityRepository<LanguageCollection> $languageRepository
35-
* @param EntityRepository<NotificationCollection> $notificationRepository
34+
* @param EntityRepository<LanguageCollection> $languageRepository
35+
* @param EntityRepository<NotificationCollection> $notificationRepository
36+
* @param EntityRepository<PluginCollection> $pluginRepository
3637
*/
3738
public function __construct(
3839
private EntityRepository $availableOpensourcePluginRepository,
@@ -41,6 +42,7 @@ public function __construct(
4142
private CacheInterface $cache,
4243
private EntityRepository $languageRepository,
4344
private EntityRepository $notificationRepository,
45+
private EntityRepository $pluginRepository,
4446
private string $shopwareVersion,
4547
) {
4648
}
@@ -126,6 +128,10 @@ public function execute(string|PackageIndexEntry $packageInformation, \DateTimeI
126128
$pluginData['lastSeenAt'] = $now;
127129
$pluginData['lastCommitTime'] = $packageInformation->latestCommitTime;
128130

131+
if (is_null($plugin) || is_null($plugin->getPluginId())) {
132+
$pluginData['pluginId'] = $this->determineExistingPluginId($pluginData, $context);
133+
}
134+
129135
$this->availableOpensourcePluginRepository->upsert([$pluginData], $context);
130136

131137
if (!is_null($plugin)) {
@@ -251,23 +257,36 @@ private function loadLanguageId(string $locale): string
251257
private function handleUpdateNotification(
252258
AvailableOpensourcePluginEntity $plugin,
253259
array $pluginData,
254-
Context $context
260+
Context $context,
255261
): void {
256-
if (is_null($swPlugin = $plugin->getPlugin()) || is_null($swPlugin->getInstalledAt())) {
262+
$swPlugin = $plugin->getPlugin() ?? (isset($pluginData['pluginId']) ? $this->pluginRepository->search(
263+
new Criteria([$pluginData['pluginId']]),
264+
$context
265+
)->first() : null);
266+
267+
if (is_null($swPlugin) || is_null($swPlugin->getInstalledAt())) {
257268
return;
258269
}
259270

260-
if (version_compare($pluginData['availableVersion'], $swPlugin->getVersion()) !== 1) {
271+
if (1 !== version_compare($pluginData['availableVersion'], $swPlugin->getVersion())) {
261272
return;
262273
}
263274

264275
$context->scope(Context::SYSTEM_SCOPE, function (Context $context) use ($swPlugin): void {
265276
$this->notificationRepository->create([[
266277
'id' => Uuid::randomHex(),
267278
'status' => 'info',
268-
'message' => 'Update available for plugin ' . $swPlugin->getName(),
279+
'message' => 'Update available for plugin '.$swPlugin->getName(),
269280
'requiredPrivileges' => [],
270281
]], $context);
271282
});
272283
}
284+
285+
private function determineExistingPluginId(array $pluginData, Context $context): ?string
286+
{
287+
return $this->pluginRepository->searchIds(
288+
(new Criteria())->addFilter(new EqualsFilter('composerName', $pluginData['packageName'])),
289+
$context
290+
)->firstId();
291+
}
273292
}

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<argument type="service" id="cache.app"/>
2828
<argument type="service" id="language.repository"/>
2929
<argument type="service" id="notification.repository" />
30+
<argument type="service" id="plugin.repository" />
3031
<argument>%kernel.shopware_version%</argument>
3132
</service>
3233

0 commit comments

Comments
 (0)