Skip to content

Commit 57782c5

Browse files
committed
feat: use plugin id in controller
1 parent ac015ef commit 57782c5

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/Controller/InstallController.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
namespace NuonicPluginInstaller\Controller;
66

7+
use NuonicPluginInstaller\Core\Framework\Plugin\AvailableOpensourcePlugin\AvailableOpensourcePluginCollection;
8+
use NuonicPluginInstaller\Core\Framework\Plugin\AvailableOpensourcePlugin\AvailableOpensourcePluginEntity;
79
use NuonicPluginInstaller\Service\PackageService;
810
use NuonicPluginInstaller\Struct\PackageVersion;
911
use OpenApi\Attributes as OA;
1012
use Shopware\Core\Framework\Context;
13+
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
14+
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
1115
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1216
use Symfony\Component\HttpFoundation\JsonResponse;
1317
use Symfony\Component\HttpFoundation\Request;
@@ -17,9 +21,14 @@
1721
#[Route(defaults: ['_routeScope' => ['api']])]
1822
class 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);

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797

9898
<service id="NuonicPluginInstaller\Controller\InstallController">
9999
<argument type="service" id="NuonicPluginInstaller\Service\PackageService" />
100+
<argument type="service" id="nuonic_available_opensource_plugin.repository" />
100101
<call method="setContainer">
101102
<argument type="service" id="service_container"/>
102103
</call>

src/ScheduledTask/LoadPluginInfo/LoadPluginInfoScheduledTaskHandler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44

55
namespace NuonicPluginInstaller\ScheduledTask\LoadPluginInfo;
66

7-
use NuonicPluginInstaller\Action\LoadIndexAction;
87
use NuonicPluginInstaller\Infrastructure\Message\LoadSinglePluginInfoMessage;
9-
use NuonicPluginInstaller\ScheduledTask\LoadIndex\LoadIndexScheduledTask;
108
use NuonicPluginInstaller\Service\IndexFileServiceInterface;
119
use Psr\Log\LoggerInterface;
1210
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
1311
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskCollection;
1412
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
15-
use Symfony\Component\Config\Loader\LoaderResolver;
1613
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
1714
use Symfony\Component\Messenger\MessageBusInterface;
1815

0 commit comments

Comments
 (0)