diff options
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Notification/Manager.php | 11 | ||||
-rw-r--r-- | lib/public/Notification/IApp.php | 3 | ||||
-rw-r--r-- | lib/public/Notification/IncompleteNotificationException.php | 43 |
5 files changed, 54 insertions, 5 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 54e6d165e83..0b2d5b3b38f 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -567,6 +567,7 @@ return array( 'OCP\\Notification\\IManager' => $baseDir . '/lib/public/Notification/IManager.php', 'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php', 'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php', + 'OCP\\Notification\\IncompleteNotificationException' => $baseDir . '/lib/public/Notification/IncompleteNotificationException.php', 'OCP\\Notification\\InvalidValueException' => $baseDir . '/lib/public/Notification/InvalidValueException.php', 'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php', 'OCP\\OCM\\Exceptions\\OCMArgumentException' => $baseDir . '/lib/public/OCM/Exceptions/OCMArgumentException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 054d9fa9bc8..b22f3a5affa 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -600,6 +600,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Notification\\IManager' => __DIR__ . '/../../..' . '/lib/public/Notification/IManager.php', 'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php', 'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php', + 'OCP\\Notification\\IncompleteNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteNotificationException.php', 'OCP\\Notification\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Notification/InvalidValueException.php', 'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php', 'OCP\\OCM\\Exceptions\\OCMArgumentException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMArgumentException.php', diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index 348ddb03df9..8bb6e1defe0 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -35,6 +35,7 @@ use OCP\Notification\IApp; use OCP\Notification\IDeferrableApp; use OCP\Notification\IDismissableNotifier; use OCP\Notification\IManager; +use OCP\Notification\IncompleteNotificationException; use OCP\Notification\INotification; use OCP\Notification\INotifier; use OCP\RichObjectStrings\IValidator; @@ -300,13 +301,11 @@ class Manager implements IManager { } /** - * @param INotification $notification - * @throws \InvalidArgumentException When the notification is not valid - * @since 8.2.0 + * {@inheritDoc} */ public function notify(INotification $notification): void { if (!$notification->isValid()) { - throw new \InvalidArgumentException('The given notification is invalid'); + throw new IncompleteNotificationException('The given notification is invalid'); } $apps = $this->getApps(); @@ -314,7 +313,11 @@ class Manager implements IManager { foreach ($apps as $app) { try { $app->notify($notification); + } catch (IncompleteNotificationException) { } catch (\InvalidArgumentException $e) { + // todo 33.0.0 Log as warning + // todo 39.0.0 Log as error + $this->logger->debug(get_class($app) . '::notify() threw \InvalidArgumentException which is deprecated. Throw \OCP\Notification\IncompleteNotificationException when the notification is incomplete for your app and otherwise handle all \InvalidArgumentException yourself.'); } } } diff --git a/lib/public/Notification/IApp.php b/lib/public/Notification/IApp.php index 6abb9a823e5..a3ef2771c8a 100644 --- a/lib/public/Notification/IApp.php +++ b/lib/public/Notification/IApp.php @@ -32,8 +32,9 @@ namespace OCP\Notification; interface IApp { /** * @param INotification $notification - * @throws \InvalidArgumentException When the notification is not valid + * @throws IncompleteNotificationException When the notification does not have all required fields set * @since 9.0.0 + * @since 30.0.0 throws {@see IncompleteNotificationException} instead of \InvalidArgumentException */ public function notify(INotification $notification): void; diff --git a/lib/public/Notification/IncompleteNotificationException.php b/lib/public/Notification/IncompleteNotificationException.php new file mode 100644 index 00000000000..31551389b43 --- /dev/null +++ b/lib/public/Notification/IncompleteNotificationException.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2024 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.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 OCP\Notification; + +/** + * Thrown when {@see \OCP\Notification\IManager::notify()} is called with a notification + * that does not have all required fields set: + * + * - app + * - user + * - dateTime + * - objectType + * - objectId + * - subject + * + * @since 30.0.0 + */ +class IncompleteNotificationException extends \InvalidArgumentException { +} |