Skip to content

Commit 7edead7

Browse files
committed
Merge branch 'next-14790/delete-integration-for-app-on-app-delete' into 'trunk'
NEXT-14790 - Delete integration for app when the app gets deleted See merge request shopware/6/product/platform!5032
2 parents 7c584e7 + e173060 commit 7edead7

File tree

4 files changed

+47
-68
lines changed

4 files changed

+47
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Delete integration for app when the app gets deleted
3+
issue: NEXT-14790
4+
---
5+
# Core
6+
* Changed `\Shopware\Core\Framework\App\Lifecycle\AppLifecycle::removeAppAndRole()` to additionally remove the integration of the app.

src/Core/Framework/App/Lifecycle/AppLifecycle.php

+29-67
Original file line numberDiff line numberDiff line change
@@ -39,82 +39,40 @@
3939
*/
4040
class AppLifecycle extends AbstractAppLifecycle
4141
{
42-
/**
43-
* @var EntityRepositoryInterface
44-
*/
45-
private $appRepository;
42+
private EntityRepositoryInterface $appRepository;
4643

47-
/**
48-
* @var PermissionPersister
49-
*/
50-
private $permissionPersister;
44+
private PermissionPersister $permissionPersister;
5145

52-
/**
53-
* @var CustomFieldPersister
54-
*/
55-
private $customFieldPersister;
46+
private CustomFieldPersister $customFieldPersister;
5647

57-
/**
58-
* @var AbstractAppLoader
59-
*/
60-
private $appLoader;
48+
private AbstractAppLoader $appLoader;
6149

62-
/**
63-
* @var EventDispatcherInterface
64-
*/
65-
private $eventDispatcher;
50+
private EventDispatcherInterface $eventDispatcher;
6651

67-
/**
68-
* @var AppRegistrationService
69-
*/
70-
private $registrationService;
52+
private AppRegistrationService $registrationService;
7153

72-
/**
73-
* @var AppStateService
74-
*/
75-
private $appStateService;
54+
private AppStateService $appStateService;
7655

77-
/**
78-
* @var ActionButtonPersister
79-
*/
80-
private $actionButtonPersister;
56+
private ActionButtonPersister $actionButtonPersister;
8157

82-
/**
83-
* @var TemplatePersister
84-
*/
85-
private $templatePersister;
58+
private TemplatePersister $templatePersister;
8659

87-
/**
88-
* @var WebhookPersister
89-
*/
90-
private $webhookPersister;
60+
private WebhookPersister $webhookPersister;
9161

9262
/**
9363
* @internal (flag:FEATURE_NEXT_14357) make persister not nullable on removal
94-
*
95-
* @var PaymentMethodPersister|null
9664
*/
97-
private $paymentMethodPersister;
65+
private ?PaymentMethodPersister $paymentMethodPersister;
9866

99-
/**
100-
* @var EntityRepositoryInterface
101-
*/
102-
private $languageRepository;
67+
private EntityRepositoryInterface $languageRepository;
10368

104-
/*
105-
* @var SystemConfigService
106-
*/
107-
private $systemConfigService;
69+
private SystemConfigService $systemConfigService;
10870

109-
/*
110-
* @var ConfigValidator
111-
*/
112-
private $configValidator;
71+
private ConfigValidator $configValidator;
11372

114-
/**
115-
* @var string
116-
*/
117-
private $projectDir;
73+
private string $projectDir;
74+
75+
private EntityRepositoryInterface $integrationRepository;
11876

11977
public function __construct(
12078
EntityRepositoryInterface $appRepository,
@@ -131,6 +89,7 @@ public function __construct(
13189
EntityRepositoryInterface $languageRepository,
13290
SystemConfigService $systemConfigService,
13391
ConfigValidator $configValidator,
92+
EntityRepositoryInterface $integrationRepository,
13493
string $projectDir
13594
) {
13695
$this->appRepository = $appRepository;
@@ -148,6 +107,7 @@ public function __construct(
148107
$this->languageRepository = $languageRepository;
149108
$this->systemConfigService = $systemConfigService;
150109
$this->configValidator = $configValidator;
110+
$this->integrationRepository = $integrationRepository;
151111
}
152112

153113
public function getDecorated(): AbstractAppLifecycle
@@ -195,10 +155,10 @@ public function delete(string $appName, array $app, Context $context): void
195155
$appEntity = $this->loadApp($app['id'], $context);
196156

197157
if ($appEntity->isActive()) {
198-
$this->appStateService->deactivateApp($app['id'], $context);
158+
$this->appStateService->deactivateApp($appEntity->getId(), $context);
199159
}
200160

201-
$this->removeAppAndRole($app['id'], $app['roleId'], $context);
161+
$this->removeAppAndRole($appEntity, $context);
202162
}
203163

204164
private function updateApp(
@@ -231,7 +191,7 @@ private function updateApp(
231191
try {
232192
$this->registrationService->registerApp($manifest, $id, $secretAccessKey, $context);
233193
} catch (AppRegistrationException $e) {
234-
$this->removeAppAndRole($id, $roleId, $context);
194+
$this->removeAppAndRole($app, $context);
235195

236196
throw $e;
237197
}
@@ -280,17 +240,18 @@ private function updateApp(
280240
return $app;
281241
}
282242

283-
private function removeAppAndRole(string $appId, string $roleId, Context $context): void
243+
private function removeAppAndRole(AppEntity $app, Context $context): void
284244
{
285245
// throw event before deleting app from db as it may be delivered via webhook to the deleted app
286246
$this->eventDispatcher->dispatch(
287-
new AppDeletedEvent($appId, $context)
247+
new AppDeletedEvent($app->getId(), $context)
288248
);
289249

290-
$context->scope(Context::SYSTEM_SCOPE, function (Context $context) use ($appId): void {
291-
$this->appRepository->delete([['id' => $appId]], $context);
250+
$context->scope(Context::SYSTEM_SCOPE, function (Context $context) use ($app): void {
251+
$this->appRepository->delete([['id' => $app->getId()]], $context);
252+
$this->integrationRepository->delete([['id' => $app->getIntegrationId()]], $context);
292253
});
293-
$this->permissionPersister->removeRole($roleId);
254+
$this->permissionPersister->removeRole($app->getAclRoleId());
294255
}
295256

296257
private function updateMetadata(array $metadata, Context $context): void
@@ -309,6 +270,7 @@ private function enrichInstallMetadata(Manifest $manifest, array $metadata, stri
309270
'writeAccess' => true,
310271
'accessKey' => AccessKeyHelper::generateAccessKey('integration'),
311272
'secretAccessKey' => $secret,
273+
'admin' => false,
312274
];
313275
$metadata['aclRole'] = [
314276
'id' => $roleId,

src/Core/Framework/DependencyInjection/app.xml

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<argument type="service" id="language.repository"/>
173173
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
174174
<argument type="service" id="Shopware\Core\Framework\App\Validation\ConfigValidator"/>
175+
<argument type="service" id="integration.repository"/>
175176
<argument type="string">%kernel.project_dir%</argument>
176177
</service>
177178

src/Core/Framework/Test/App/Lifecycle/AppLifecycleTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ public function testInstall(): void
102102

103103
static::assertTrue($eventWasReceived);
104104
$this->eventDispatcher->removeListener(AppInstalledEvent::class, $onAppInstalled);
105+
$criteria = new Criteria();
106+
$criteria->addAssociation('integration');
105107
/** @var AppCollection $apps */
106-
$apps = $this->appRepository->search(new Criteria(), $this->context)->getEntities();
108+
$apps = $this->appRepository->search($criteria, $this->context)->getEntities();
107109

108110
static::assertCount(1, $apps);
109111
static::assertEquals('test', $apps->first()->getName());
@@ -123,6 +125,7 @@ public function testInstall(): void
123125

124126
static::assertEquals($appId, $apps->first()->getId());
125127
static::assertFalse($apps->first()->isConfigurable());
128+
static::assertFalse($apps->first()->getIntegration()->getAdmin());
126129
$this->assertDefaultActionButtons();
127130
$this->assertDefaultModules($apps->first());
128131
$this->assertDefaultPrivileges($apps->first()->getAclRoleId());
@@ -776,6 +779,7 @@ public function testDelete(): void
776779
{
777780
$appId = Uuid::randomHex();
778781
$roleId = Uuid::randomHex();
782+
$integrationId = Uuid::randomHex();
779783

780784
$this->appRepository->create([[
781785
'id' => $appId,
@@ -794,6 +798,7 @@ public function testDelete(): void
794798
],
795799
],
796800
'integration' => [
801+
'id' => $integrationId,
797802
'label' => 'test',
798803
'writeAccess' => false,
799804
'accessKey' => 'test',
@@ -829,6 +834,11 @@ public function testDelete(): void
829834
$roles = $aclRoleRepository->searchIds(new Criteria([$roleId]), $this->context)->getIds();
830835
static::assertCount(0, $roles);
831836

837+
/** @var EntityRepositoryInterface $integrationRepository */
838+
$integrationRepository = $this->getContainer()->get('integration.repository');
839+
$integrations = $integrationRepository->searchIds(new Criteria([$integrationId]), $this->context)->getIds();
840+
static::assertCount(0, $integrations);
841+
832842
$criteria = new Criteria();
833843
$criteria->addFilter(new EqualsFilter('appId', $appId));
834844
$apps = $this->actionButtonRepository->searchIds($criteria, $this->context)->getIds();

0 commit comments

Comments
 (0)