|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Flownative\Canto; |
| 5 | + |
| 6 | +/* |
| 7 | + * This file is part of the Flownative.Canto package. |
| 8 | + * |
| 9 | + * (c) Karsten Dambekalns, Flownative GmbH - www.flownative.com |
| 10 | + * |
| 11 | + * This package is Open Source Software. For the full copyright and license |
| 12 | + * information, please view the LICENSE file which was distributed with this |
| 13 | + * source code. |
| 14 | + */ |
| 15 | + |
| 16 | +use Doctrine\ORM\EntityManagerInterface; |
| 17 | +use Flownative\Canto\Domain\Repository\AccountAuthorizationRepository; |
| 18 | +use Flownative\OAuth2\Client\Authorization; |
| 19 | +use Neos\Flow\Core\Bootstrap; |
| 20 | +use Neos\Flow\Package\Package as BasePackage; |
| 21 | +use Neos\Neos\Domain\Model\User; |
| 22 | +use Neos\Neos\Domain\Service\UserService; |
| 23 | + |
| 24 | +class Package extends BasePackage |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @param Bootstrap $bootstrap The current bootstrap |
| 28 | + * @return void |
| 29 | + */ |
| 30 | + public function boot(Bootstrap $bootstrap) |
| 31 | + { |
| 32 | + $dispatcher = $bootstrap->getSignalSlotDispatcher(); |
| 33 | + $dispatcher->connect( |
| 34 | + UserService::class, |
| 35 | + 'userDeleted', |
| 36 | + function (User $user) use ($bootstrap) { |
| 37 | + $accountAuthorizationRepository = $bootstrap->getObjectManager()->get(AccountAuthorizationRepository::class); |
| 38 | + $entityManager = $bootstrap->getObjectManager()->get(EntityManagerInterface::class); |
| 39 | + |
| 40 | + foreach ($user->getAccounts() as $account) { |
| 41 | + $accountAuthorization = $accountAuthorizationRepository->findOneByFlowAccountIdentifier($account->getAccountIdentifier()); |
| 42 | + if ($accountAuthorization !== null) { |
| 43 | + $authorizationId = $accountAuthorization->getAuthorizationId(); |
| 44 | + $authorization = $entityManager->find(Authorization::class, ['authorizationId' => $authorizationId]); |
| 45 | + if ($authorization instanceof Authorization) { |
| 46 | + $entityManager->remove($authorization); |
| 47 | + } |
| 48 | + |
| 49 | + $accountAuthorizationRepository->remove($accountAuthorization); |
| 50 | + } |
| 51 | + } |
| 52 | + }, |
| 53 | + '', |
| 54 | + false |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
0 commit comments