aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_reminders/lib
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2023-08-03 15:42:14 -0700
committerChristopher Ng <chrng8@gmail.com>2023-08-03 15:43:35 -0700
commita806bd0d3c53d7d12fe2c0e9a6559f1ac71ca86f (patch)
tree1e8cb6af0e5e9d0a578bfd9798374b91dc36df90 /apps/files_reminders/lib
parent5a11535c51ae0277f6bb0af048215e329b6068d0 (diff)
downloadnextcloud-server-a806bd0d3c53d7d12fe2c0e9a6559f1ac71ca86f.tar.gz
nextcloud-server-a806bd0d3c53d7d12fe2c0e9a6559f1ac71ca86f.zip
enh: handle user deleted
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/files_reminders/lib')
-rw-r--r--apps/files_reminders/lib/AppInfo/Application.php4
-rw-r--r--apps/files_reminders/lib/Listener/UserDeletedListener.php47
-rw-r--r--apps/files_reminders/lib/Service/ReminderService.php7
3 files changed, 58 insertions, 0 deletions
diff --git a/apps/files_reminders/lib/AppInfo/Application.php b/apps/files_reminders/lib/AppInfo/Application.php
index 1e4813e1ec7..d35bd5c5de2 100644
--- a/apps/files_reminders/lib/AppInfo/Application.php
+++ b/apps/files_reminders/lib/AppInfo/Application.php
@@ -27,12 +27,14 @@ declare(strict_types=1);
namespace OCA\FilesReminders\AppInfo;
use OCA\FilesReminders\Listener\NodeDeletedListener;
+use OCA\FilesReminders\Listener\UserDeletedListener;
use OCA\FilesReminders\Notification\Notifier;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Events\Node\NodeDeletedEvent;
+use OCP\User\Events\UserDeletedEvent;
class Application extends App implements IBootstrap {
public const APP_ID = 'files_reminders';
@@ -46,6 +48,8 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerNotifierService(Notifier::class);
+
$context->registerEventListener(NodeDeletedEvent::class, NodeDeletedListener::class);
+ $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
}
}
diff --git a/apps/files_reminders/lib/Listener/UserDeletedListener.php b/apps/files_reminders/lib/Listener/UserDeletedListener.php
new file mode 100644
index 00000000000..b95102c1cc2
--- /dev/null
+++ b/apps/files_reminders/lib/Listener/UserDeletedListener.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2023 Christopher Ng <chrng8@gmail.com>
+ *
+ * @author Christopher Ng <chrng8@gmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\FilesReminders\Listener;
+
+use OCA\FilesReminders\Service\ReminderService;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\User\Events\UserDeletedEvent;
+
+class UserDeletedListener implements IEventListener {
+ public function __construct(
+ private ReminderService $reminderService,
+ ) {}
+
+ public function handle(Event $event): void {
+ if (!($event instanceof UserDeletedEvent)) {
+ return;
+ }
+
+ $user = $event->getUser();
+ $this->reminderService->removeAllForUser($user);
+ }
+}
diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php
index 91652a4e0be..5c7193259c1 100644
--- a/apps/files_reminders/lib/Service/ReminderService.php
+++ b/apps/files_reminders/lib/Service/ReminderService.php
@@ -128,6 +128,13 @@ class ReminderService {
}
}
+ public function removeAllForUser(IUser $user): void {
+ $reminders = $this->reminderMapper->findAllForUser($user);
+ foreach ($reminders as $reminder) {
+ $this->reminderMapper->delete($reminder);
+ }
+ }
+
/**
* @throws DoesNotExistException
* @throws UserNotFoundException