44
55namespace NuonicPluginInstaller \Controller ;
66
7+ use NuonicPluginInstaller \Core \Framework \Plugin \AvailableOpensourcePlugin \AvailableOpensourcePluginCollection ;
8+ use NuonicPluginInstaller \Core \Framework \Plugin \AvailableOpensourcePlugin \AvailableOpensourcePluginEntity ;
79use NuonicPluginInstaller \Service \PackageService ;
810use NuonicPluginInstaller \Struct \PackageVersion ;
911use OpenApi \Attributes as OA ;
1012use Shopware \Core \Framework \Context ;
13+ use Shopware \Core \Framework \DataAbstractionLayer \EntityRepository ;
14+ use Shopware \Core \Framework \DataAbstractionLayer \Search \Criteria ;
1115use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1216use Symfony \Component \HttpFoundation \JsonResponse ;
1317use Symfony \Component \HttpFoundation \Request ;
1721#[Route(defaults: ['_routeScope ' => ['api ' ]])]
1822class InstallController extends AbstractController
1923{
24+ /**
25+ * @param EntityRepository<AvailableOpensourcePluginCollection> $openSourcePluginRepository
26+ */
2027 public function __construct (
2128 private readonly PackageService $ packageService ,
22- ) {}
29+ private readonly EntityRepository $ openSourcePluginRepository ,
30+ ) {
31+ }
2332
2433 #[OA \Post(
2534 path: '/api/_action/nuonic-plugin-installer/install ' ,
@@ -40,13 +49,21 @@ public function __construct(
4049 public function execute (Request $ request , Context $ context ): Response
4150 {
4251 $ requestData = $ request ->toArray ();
43- if (!isset ($ requestData ['package ' ], $ requestData [ ' version ' ])) {
52+ if (!isset ($ requestData ['openSourcePluginId ' ])) {
4453 $ this ->malformedRequestError ();
4554 }
4655
56+ /** @var AvailableOpensourcePluginEntity $plugin */
57+ $ plugin = $ this ->openSourcePluginRepository ->search (new Criteria ([$ requestData ['openSourcePluginId ' ]]), $ context )
58+ ->first ();
59+
60+ if (!$ plugin ) {
61+ throw $ this ->createNotFoundException ();
62+ }
63+
4764 $ this ->packageService ->install (new PackageVersion (
48- $ requestData [ ' package ' ] ,
49- $ requestData [ ' version ' ]
65+ $ plugin -> getPackageName () ,
66+ $ plugin -> getAvailableVersion (),
5067 ), $ context );
5168
5269 return new Response (status: 201 );
0 commit comments