1515use Shopware \Core \Framework \DataAbstractionLayer \EntityRepository ;
1616use Shopware \Core \Framework \DataAbstractionLayer \Search \Criteria ;
1717use Shopware \Core \Framework \DataAbstractionLayer \Search \Filter \EqualsFilter ;
18+ use Shopware \Core \Framework \Plugin \PluginCollection ;
1819use Shopware \Core \Framework \Uuid \Uuid ;
1920use Shopware \Core \System \Language \LanguageCollection ;
2021use Symfony \Component \Yaml \Yaml ;
2829
2930readonly 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}
0 commit comments