Skip to content

Commit

Permalink
refactor: move to new activity exception
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <anna@nextcloud.com>
  • Loading branch information
miaulalala committed Sep 17, 2024
1 parent 4e64a6e commit 1ce46c1
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 41 deletions.
9 changes: 5 additions & 4 deletions apps/comments/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\Comments\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand Down Expand Up @@ -32,12 +33,12 @@ public function __construct(
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'comments') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('comments', $language);
Expand All @@ -59,9 +60,9 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
}

return $this->parseLongVersion($event);
} else {
throw new \InvalidArgumentException();
}
throw new UnknownActivityException();

}

/**
Expand Down
7 changes: 4 additions & 3 deletions apps/dav/lib/CalDAV/Activity/Provider/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\DAV\CalDAV\Activity\Provider;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -59,12 +60,12 @@ public function __construct(IFactory $languageFactory, IURLGenerator $url, IMana
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('dav', $language);
Expand Down Expand Up @@ -122,7 +123,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') {
$subject = $this->l->t('{actor} unshared calendar {calendar} from group {group}');
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$parsedParameters = $this->getParameters($event);
Expand Down
7 changes: 4 additions & 3 deletions apps/dav/lib/CalDAV/Activity/Provider/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace OCA\DAV\CalDAV\Activity\Provider;

use OC_App;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -106,12 +107,12 @@ protected function generateObjectParameter(array $eventData, string $affectedUse
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_event') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('dav', $language);
Expand Down Expand Up @@ -147,7 +148,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_RESTORE . '_event_self') {
$subject = $this->l->t('You restored event {event} of calendar {calendar}');
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$parsedParameters = $this->getParameters($event);
Expand Down
7 changes: 4 additions & 3 deletions apps/dav/lib/CalDAV/Activity/Provider/Todo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\DAV\CalDAV\Activity\Provider;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;

class Todo extends Event {
Expand All @@ -14,12 +15,12 @@ class Todo extends Event {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'dav' || $event->getType() !== 'calendar_todo') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('dav', $language);
Expand Down Expand Up @@ -55,7 +56,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
} elseif ($event->getSubject() === self::SUBJECT_OBJECT_MOVE . '_todo_self') {
$subject = $this->l->t('You moved to-do {todo} from list {sourceCalendar} to list {targetCalendar}');
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$parsedParameters = $this->getParameters($event);
Expand Down
7 changes: 4 additions & 3 deletions apps/dav/lib/CardDAV/Activity/Provider/Addressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\DAV\CardDAV\Activity\Provider;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -52,11 +53,11 @@ public function __construct(IFactory $languageFactory,
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'dav' || $event->getType() !== 'contacts') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$l = $this->languageFactory->get('dav', $language);
Expand Down Expand Up @@ -102,7 +103,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
} elseif ($event->getSubject() === self::SUBJECT_UNSHARE_GROUP . '_by') {
$subject = $l->t('{actor} unshared address book {addressbook} from group {group}');
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$parsedParameters = $this->getParameters($event, $l);
Expand Down
7 changes: 4 additions & 3 deletions apps/dav/lib/CardDAV/Activity/Provider/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\DAV\CardDAV\Activity\Provider;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -54,11 +55,11 @@ public function __construct(IFactory $languageFactory,
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'dav' || $event->getType() !== 'contacts') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$l = $this->languageFactory->get('dav', $language);
Expand All @@ -82,7 +83,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
} elseif ($event->getSubject() === self::SUBJECT_UPDATE . '_self') {
$subject = $l->t('You updated contact {card} in address book {addressbook}');
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$parsedParameters = $this->getParameters($event, $l);
Expand Down
5 changes: 3 additions & 2 deletions apps/files/lib/Activity/FavoriteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\Files\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -50,12 +51,12 @@ public function __construct(IFactory $languageFactory, IURLGenerator $url, IMana
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('files', $language);
Expand Down
5 changes: 3 additions & 2 deletions apps/files/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\Files\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -79,12 +80,12 @@ public function __construct(IFactory $languageFactory,
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'files') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('files', $language);
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/Activity/Providers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\Files_Sharing\Activity\Providers;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -65,12 +66,12 @@ public function __construct(IFactory $languageFactory,
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'files_sharing') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('files_sharing', $language);
Expand Down
6 changes: 3 additions & 3 deletions apps/settings/lib/Activity/GroupProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace OCA\Settings\Activity;

use InvalidArgumentException;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct(L10nFactory $l10n,

public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getType() !== 'group_settings') {
throw new InvalidArgumentException();
throw new UnknownActivityException();
}

$l = $this->l10n->get('settings', $language);
Expand Down Expand Up @@ -95,7 +95,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
}
break;
default:
throw new InvalidArgumentException();
throw new UnknownActivityException();
}

$this->setSubjects($event, $subject, $parsedParameters);
Expand Down
7 changes: 4 additions & 3 deletions apps/settings/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\Settings\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand Down Expand Up @@ -60,12 +61,12 @@ public function __construct(IFactory $languageFactory,
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'settings') {
throw new \InvalidArgumentException('Unknown app');
throw new UnknownActivityException('Unknown app');
}

$this->l = $this->languageFactory->get('settings', $language);
Expand Down Expand Up @@ -105,7 +106,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
} elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_REVOKED) {
$subject = $this->l->t('You revoked filesystem access from app password "{token}"');
} else {
throw new \InvalidArgumentException('Unknown subject');
throw new UnknownActivityException('Unknown subject');
}

$parsedParameters = $this->getParameters($event);
Expand Down
6 changes: 3 additions & 3 deletions apps/settings/lib/Activity/SecurityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
namespace OCA\Settings\Activity;

use InvalidArgumentException;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand All @@ -34,7 +34,7 @@ public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IMan

public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getType() !== 'security') {
throw new InvalidArgumentException();
throw new UnknownActivityException();
}

$l = $this->l10n->get('settings', $language);
Expand Down Expand Up @@ -85,7 +85,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
}
break;
default:
throw new InvalidArgumentException();
throw new UnknownActivityException();
}
return $event;
}
Expand Down
5 changes: 3 additions & 2 deletions apps/sharebymail/lib/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\ShareByMail;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand Down Expand Up @@ -62,12 +63,12 @@ public function __construct(IFactory $languageFactory, IURLGenerator $url, IMana
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'sharebymail') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('sharebymail', $language);
Expand Down
5 changes: 3 additions & 2 deletions apps/systemtags/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace OCA\SystemTags\Activity;

use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
Expand Down Expand Up @@ -54,12 +55,12 @@ public function __construct(IFactory $languageFactory, IURLGenerator $url, IMana
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'systemtags') {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->l = $this->languageFactory->get('systemtags', $language);
Expand Down
Loading

0 comments on commit 1ce46c1

Please sign in to comment.