From 1063769a77ed521fef49a1ac12b4679f12bc2e26 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Mon, 18 May 2026 07:26:58 +0200 Subject: [PATCH] fix(files_sharing): Use UnknownActivityException Signed-off-by: provokateurin --- apps/files_sharing/lib/Activity/Providers/Base.php | 13 +++++-------- .../lib/Activity/Providers/Downloads.php | 13 +++++++------ .../files_sharing/lib/Activity/Providers/Groups.php | 12 +++++++----- .../lib/Activity/Providers/PublicLinks.php | 13 ++++++++----- .../lib/Activity/Providers/RemoteShares.php | 11 ++++++----- apps/files_sharing/lib/Activity/Providers/Users.php | 13 ++++++++----- 6 files changed, 41 insertions(+), 34 deletions(-) diff --git a/apps/files_sharing/lib/Activity/Providers/Base.php b/apps/files_sharing/lib/Activity/Providers/Base.php index 1a58739555aab..a558e73aabdba 100644 --- a/apps/files_sharing/lib/Activity/Providers/Base.php +++ b/apps/files_sharing/lib/Activity/Providers/Base.php @@ -55,7 +55,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { if ($this->activityManager->isFormattingFilteredObject()) { try { return $this->parseShortVersion($event); - } catch (\InvalidArgumentException $e) { + } catch (UnknownActivityException $e) { // Ignore and simply use the long version... } } @@ -66,7 +66,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ abstract protected function parseShortVersion(IEvent $event); @@ -75,14 +75,11 @@ abstract protected function parseShortVersion(IEvent $event); * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ abstract protected function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null); - /** - * @throws \InvalidArgumentException - */ protected function setSubjects(IEvent $event, string $subject, array $parameters): void { $event->setRichSubject($subject, $parameters); } @@ -91,7 +88,7 @@ protected function setSubjects(IEvent $event, string $subject, array $parameters * @param array|string $parameter * @param IEvent|null $event * @return array - * @throws \InvalidArgumentException + * @throws UnknownActivityException */ protected function getFile($parameter, ?IEvent $event = null) { if (is_array($parameter)) { @@ -101,7 +98,7 @@ protected function getFile($parameter, ?IEvent $event = null) { $path = $parameter; $id = (string)$event->getObjectId(); } else { - throw new \InvalidArgumentException('Could not generate file parameter'); + throw new UnknownActivityException('Could not generate file parameter'); } return [ diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php index e2d8703c3a1bd..3ed631531d3b3 100644 --- a/apps/files_sharing/lib/Activity/Providers/Downloads.php +++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php @@ -6,6 +6,7 @@ */ namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; class Downloads extends Base { @@ -18,7 +19,7 @@ class Downloads extends Base { /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -32,7 +33,7 @@ public function parseShortVersion(IEvent $event) { || $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { $subject = $this->l->t('Downloaded by {email}'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -49,7 +50,7 @@ public function parseShortVersion(IEvent $event) { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -71,7 +72,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { $subject = $this->l->t('{email} downloaded {file}'); $this->setSubjects($event, $subject, $parsedParameters); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -86,7 +87,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { /** * @param IEvent $event * @return array - * @throws \InvalidArgumentException + * @throws UnknownActivityException */ protected function getParsedParameters(IEvent $event) { $subject = $event->getSubject(); @@ -121,6 +122,6 @@ protected function getParsedParameters(IEvent $event) { ]; } - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } } diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php index 09c450683efe2..06915298d4c2b 100644 --- a/apps/files_sharing/lib/Activity/Providers/Groups.php +++ b/apps/files_sharing/lib/Activity/Providers/Groups.php @@ -6,6 +6,7 @@ */ namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; @@ -45,7 +46,7 @@ public function __construct( /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -63,7 +64,7 @@ public function parseShortVersion(IEvent $event) { } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { $subject = $this->l->t('Share for group {group} expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -80,7 +81,7 @@ public function parseShortVersion(IEvent $event) { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -98,7 +99,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) { $subject = $this->l->t('Share for file {file} with group {group} expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -131,7 +132,8 @@ protected function getParsedParameters(IEvent $event) { 'group' => $this->generateGroupParameter($parameters[1]), ]; } - return []; + + throw new UnknownActivityException(); } /** diff --git a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php index fef5c61bd88f2..5e68baf189172 100644 --- a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php +++ b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php @@ -4,8 +4,10 @@ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; class PublicLinks extends Base { @@ -19,7 +21,7 @@ class PublicLinks extends Base { /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -39,7 +41,7 @@ public function parseShortVersion(IEvent $event) { } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { $subject = $this->l->t('Public link of {actor} expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -56,7 +58,7 @@ public function parseShortVersion(IEvent $event) { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -76,7 +78,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { $subject = $this->l->t('Public link of {actor} for {file} expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -108,6 +110,7 @@ protected function getParsedParameters(IEvent $event) { 'actor' => $this->getUser($parameters[1]), ]; } - return []; + + throw new UnknownActivityException(); } } diff --git a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php index 1c759f9348311..63822d8a5e3b3 100644 --- a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php +++ b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php @@ -6,6 +6,7 @@ */ namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\Activity\IManager; @@ -34,7 +35,7 @@ public function __construct(IFactory $languageFactory, /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -46,7 +47,7 @@ public function parseShortVersion(IEvent $event) { } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) { $subject = $this->l->t('{user} declined the remote share'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -63,7 +64,7 @@ public function parseShortVersion(IEvent $event) { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -79,7 +80,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { } elseif ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) { $subject = $this->l->t('{user} unshared {file} from you'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -119,6 +120,6 @@ protected function getParsedParameters(IEvent $event) { 'user' => $this->getUser($parameters[0]), ]; } - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } } diff --git a/apps/files_sharing/lib/Activity/Providers/Users.php b/apps/files_sharing/lib/Activity/Providers/Users.php index 30635d2c8f2a5..596529a8f7352 100644 --- a/apps/files_sharing/lib/Activity/Providers/Users.php +++ b/apps/files_sharing/lib/Activity/Providers/Users.php @@ -4,8 +4,10 @@ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\Files_Sharing\Activity\Providers; +use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; class Users extends Base { @@ -25,7 +27,7 @@ class Users extends Base { /** * @param IEvent $event * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -53,7 +55,7 @@ public function parseShortVersion(IEvent $event) { } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) { $subject = $this->l->t('Share expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -70,7 +72,7 @@ public function parseShortVersion(IEvent $event) { * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent - * @throws \InvalidArgumentException + * @throws UnknownActivityException * @since 11.0.0 */ #[\Override] @@ -98,7 +100,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) { } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) { $subject = $this->l->t('Share for file {file} expired'); } else { - throw new \InvalidArgumentException(); + throw new UnknownActivityException(); } if ($this->activityManager->getRequirePNG()) { @@ -140,6 +142,7 @@ protected function getParsedParameters(IEvent $event) { 'actor' => $this->getUser($parameters[1]), ]; } - return []; + + throw new UnknownActivityException(); } }