|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Assistant\Listener; |
| 11 | + |
| 12 | +use OCA\Assistant\Service\AssignmentsService; |
| 13 | +use OCA\Assistant\Service\ChatService; |
| 14 | +use OCA\Assistant\Service\InternalException; |
| 15 | +use OCP\EventDispatcher\Event; |
| 16 | +use OCP\EventDispatcher\IEventListener; |
| 17 | +use OCP\User\Events\UserDeletedEvent; |
| 18 | +use Psr\Log\LoggerInterface; |
| 19 | + |
| 20 | +/** |
| 21 | + * @template-implements IEventListener<UserDeletedEvent> |
| 22 | + */ |
| 23 | +class UserDeletedListener implements IEventListener { |
| 24 | + |
| 25 | + public function __construct( |
| 26 | + private ChatService $chatService, |
| 27 | + private AssignmentsService $assignmentsService, |
| 28 | + private LoggerInterface $logger, |
| 29 | + ) { |
| 30 | + } |
| 31 | + |
| 32 | + public function handle(Event $event): void { |
| 33 | + if (!($event instanceof UserDeletedEvent)) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + $userId = $event->getUid(); |
| 38 | + |
| 39 | + try { |
| 40 | + $this->assignmentsService->deleteAllForUser($userId); |
| 41 | + } catch (InternalException $e) { |
| 42 | + $this->logger->error('Error while deleting assignments for user ' . $userId, ['exception' => $e]); |
| 43 | + } |
| 44 | + |
| 45 | + try { |
| 46 | + $this->chatService->deleteAllUserChatData($userId); |
| 47 | + } catch (InternalException $e) { |
| 48 | + $this->logger->error('Error while deleting chat data for user ' . $userId, ['exception' => $e]); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments