diff options
author | Joas Schilling <coding@schilljs.com> | 2024-06-25 11:20:48 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-06-25 11:56:24 +0200 |
commit | 8130968a352bcf66606a076598fa4a58a291bc6d (patch) | |
tree | ed7d9c5bfc0d7e1b3c63348f0416d96cb51fb6ef /apps/updatenotification/lib | |
parent | 9496ce6c7a35f5a6d151b78d78a45b1c900b3b2a (diff) | |
download | nextcloud-server-8130968a352bcf66606a076598fa4a58a291bc6d.tar.gz nextcloud-server-8130968a352bcf66606a076598fa4a58a291bc6d.zip |
feat(notifications): Migrate server INotifiers to new exceptions
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/updatenotification/lib')
-rw-r--r-- | apps/updatenotification/lib/Notification/AppUpdateNotifier.php | 13 | ||||
-rw-r--r-- | apps/updatenotification/lib/Notification/Notifier.php | 10 |
2 files changed, 13 insertions, 10 deletions
diff --git a/apps/updatenotification/lib/Notification/AppUpdateNotifier.php b/apps/updatenotification/lib/Notification/AppUpdateNotifier.php index 25777db6367..353ca883aba 100644 --- a/apps/updatenotification/lib/Notification/AppUpdateNotifier.php +++ b/apps/updatenotification/lib/Notification/AppUpdateNotifier.php @@ -13,10 +13,12 @@ use OCP\App\IAppManager; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; +use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IAction; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; +use OCP\Notification\UnknownNotificationException; use Psr\Log\LoggerInterface; class AppUpdateNotifier implements INotifier { @@ -46,26 +48,27 @@ class AppUpdateNotifier implements INotifier { * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification - * @throws \InvalidArgumentException When the notification was not prepared by a notifier + * @throws UnknownNotificationException When the notification was not prepared by a notifier + * @throws AlreadyProcessedException When the app is no longer known */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== Application::APP_NAME) { - throw new \InvalidArgumentException('Unknown app'); + throw new UnknownNotificationException('Unknown app'); } if ($notification->getSubject() !== 'app_updated') { - throw new \InvalidArgumentException('Unknown subject'); + throw new UnknownNotificationException('Unknown subject'); } $appId = $notification->getSubjectParameters()[0]; $appInfo = $this->appManager->getAppInfo($appId, lang:$languageCode); if ($appInfo === null) { - throw new \InvalidArgumentException('App info not found'); + throw new AlreadyProcessedException(); } // Prepare translation factory for requested language $l = $this->l10nFactory->get(Application::APP_NAME, $languageCode); - + $icon = $this->appManager->getAppIcon($appId, true); if ($icon === null) { $icon = $this->urlGenerator->imagePath('core', 'actions/change.svg'); diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index 87f22d60f60..6f1e8514b11 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -19,6 +19,7 @@ use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; +use OCP\Notification\UnknownNotificationException; use OCP\Util; class Notifier implements INotifier { @@ -87,25 +88,24 @@ class Notifier implements INotifier { * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification - * @throws \InvalidArgumentException When the notification was not prepared by a notifier + * @throws UnknownNotificationException When the notification was not prepared by a notifier * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted * @since 9.0.0 */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'updatenotification') { - throw new \InvalidArgumentException('Unknown app id'); + throw new UnknownNotificationException('Unknown app id'); } if ($notification->getSubject() !== 'update_available' && $notification->getSubject() !== 'connection_error') { - throw new \InvalidArgumentException('Unknown subject'); + throw new UnknownNotificationException('Unknown subject'); } $l = $this->l10NFactory->get('updatenotification', $languageCode); if ($notification->getSubject() === 'connection_error') { $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0'); if ($errors === 0) { - $this->notificationManager->markProcessed($notification); - throw new \InvalidArgumentException('Update checked worked again'); + throw new AlreadyProcessedException(); } $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |