From 6d71e471e166c30c0b9abe05d36240b9f1556d8e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2019 14:29:30 +0200 Subject: Update shipped implementations of the INotifier Signed-off-by: Joas Schilling --- .../updatenotification/lib/AppInfo/Application.php | 10 +------- .../lib/Notification/Notifier.php | 29 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'apps/updatenotification') diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php index 14512bae838..91b9020d82e 100644 --- a/apps/updatenotification/lib/AppInfo/Application.php +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -71,14 +71,6 @@ class Application extends App { public function registerNotifier() { $notificationsManager = $this->getContainer()->getServer()->getNotificationManager(); - $notificationsManager->registerNotifier(function() { - return $this->getContainer()->query(Notifier::class); - }, function() { - $l = $this->getContainer()->getServer()->getL10N('updatenotification'); - return [ - 'id' => 'updatenotification', - 'name' => $l->t('Update notifications'), - ]; - }); + $notificationsManager->registerNotifier(Notifier::class); } } diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index 4e3a30f225e..44fe91c63d5 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -31,6 +31,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; @@ -79,14 +80,35 @@ class Notifier implements INotifier { $this->appVersions = $this->getAppVersions(); } + /** + * Identifier of the notifier, only use [a-z0-9_] + * + * @return string + * @since 17.0.0 + */ + public function getID(): string { + return 'updatenotification'; + } + + /** + * Human readable name describing the notifier + * + * @return string + * @since 17.0.0 + */ + public function getName(): string { + return $this->l10NFactory->get('updatenotification')->t('Update notifications'); + } + /** * @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 AlreadyProcessedException When the notification is not needed anymore and should be deleted * @since 9.0.0 */ - public function prepare(INotification $notification, $languageCode): INotification { + public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'updatenotification') { throw new \InvalidArgumentException('Unknown app id'); } @@ -142,12 +164,11 @@ class Notifier implements INotifier { * * @param INotification $notification * @param string $installedVersion - * @throws \InvalidArgumentException When the update is already installed + * @throws AlreadyProcessedException When the update is already installed */ protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { - $this->notificationManager->markProcessed($notification); - throw new \InvalidArgumentException('Update already installed'); + throw new AlreadyProcessedException(); } } -- cgit v1.2.3