diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2022-10-19 00:36:14 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-10-21 19:58:12 +0300 |
commit | 625d6d4d0cecce34a2b9c9a72ca3434f3bd88961 (patch) | |
tree | 27d46fc3a2d4e5fc0049983d289ed6acea528def /lib | |
parent | 6a3f2ff022994f32a207dc19c4ed9b478bf876ed (diff) |
improve admin notification experience
- do not stack notifications, replace them
- and replace them once a day only
- with LDAP it might end in total spam terror (also push) otherwise
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Support/Subscription/Registry.php | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/private/Support/Subscription/Registry.php b/lib/private/Support/Subscription/Registry.php index ba3642d021c..87070e7a0dc 100644 --- a/lib/private/Support/Subscription/Registry.php +++ b/lib/private/Support/Subscription/Registry.php @@ -215,19 +215,38 @@ class Registry implements IRegistry { return $userCount; } - private function notifyAboutReachedUserLimit(IManager $notificationManager) { + private function notifyAboutReachedUserLimit(IManager $notificationManager): void { $admins = $this->groupManager->get('admin')->getUsers(); - foreach ($admins as $admin) { - $notification = $notificationManager->createNotification(); - $notification->setApp('core') - ->setUser($admin->getUID()) - ->setDateTime(new \DateTime()) - ->setObject('user_limit_reached', '1') - ->setSubject('user_limit_reached'); + $notification = $notificationManager->createNotification(); + $notification->setApp('core') + ->setObject('user_limit_reached', '1') + ->setSubject('user_limit_reached'); + + if ($notificationManager->getCount($notification) > 0 + && !$this->reIssue() + ) { + return; + } + + $notificationManager->markProcessed($notification); + $notification->setDateTime(new \DateTime()); + + foreach ($admins as $admin) { + $notification->setUser($admin->getUID()); $notificationManager->notify($notification); } $this->logger->warning('The user limit was reached and the new user was not created', ['app' => 'lib']); } + + protected function reIssue(): bool { + $lastNotification = (int)$this->config->getAppValue('lib', 'last_subscription_reminder', '0'); + + if ((time() - $lastNotification) >= 86400) { + $this->config->setAppValue('lib', 'last_subscription_reminder', (string)time()); + return true; + } + return false; + } } |