From 06a8c6bc02fddffcf226271cd48083de9835429f Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Wed, 27 Oct 2021 10:35:01 +0200 Subject: [PATCH] Remove related OAuth authorization data upon user deletion Fixes #12 --- Classes/Package.php | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Classes/Package.php diff --git a/Classes/Package.php b/Classes/Package.php new file mode 100644 index 0000000..2ee5294 --- /dev/null +++ b/Classes/Package.php @@ -0,0 +1,57 @@ +getSignalSlotDispatcher(); + $dispatcher->connect( + UserService::class, + 'userDeleted', + function (User $user) use ($bootstrap) { + $accountAuthorizationRepository = $bootstrap->getObjectManager()->get(AccountAuthorizationRepository::class); + $entityManager = $bootstrap->getObjectManager()->get(EntityManagerInterface::class); + + foreach ($user->getAccounts() as $account) { + $accountAuthorization = $accountAuthorizationRepository->findOneByFlowAccountIdentifier($account->getAccountIdentifier()); + if ($accountAuthorization !== null) { + $authorizationId = $accountAuthorization->getAuthorizationId(); + $authorization = $entityManager->find(Authorization::class, ['authorizationId' => $authorizationId]); + if ($authorization instanceof Authorization) { + $entityManager->remove($authorization); + } + + $accountAuthorizationRepository->remove($accountAuthorization); + } + } + }, + '', + false + ); + } +}