aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-09-18 16:16:58 +0200
committerJoas Schilling <coding@schilljs.com>2024-09-23 12:31:59 +0200
commit096f893d46c0b8d226ca086d4086efed18f66230 (patch)
tree9efda514533c3e08ccfc9bca220938ab76c04e0f /apps/files
parent0dc23639cad1373052fdaea5ca1d1d3c092a959c (diff)
downloadnextcloud-server-096f893d46c0b8d226ca086d4086efed18f66230.tar.gz
nextcloud-server-096f893d46c0b8d226ca086d4086efed18f66230.zip
fix(activity): Update more activity providers to use new exceptionsfollowup/48086/fix-more-activity-providers
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/lib/Activity/FavoriteProvider.php14
-rw-r--r--apps/files/lib/Activity/Provider.php24
-rw-r--r--apps/files/tests/Activity/ProviderTest.php3
3 files changed, 21 insertions, 20 deletions
diff --git a/apps/files/lib/Activity/FavoriteProvider.php b/apps/files/lib/Activity/FavoriteProvider.php
index 8cfc1a83798..dd24eaedd2c 100644
--- a/apps/files/lib/Activity/FavoriteProvider.php
+++ b/apps/files/lib/Activity/FavoriteProvider.php
@@ -64,7 +64,7 @@ class FavoriteProvider implements IProvider {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
- } catch (\InvalidArgumentException $e) {
+ } catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
@@ -75,10 +75,10 @@ class FavoriteProvider implements IProvider {
/**
* @param IEvent $event
* @return IEvent
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
* @since 11.0.0
*/
- public function parseShortVersion(IEvent $event) {
+ public function parseShortVersion(IEvent $event): IEvent {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$event->setParsedSubject($this->l->t('Added to favorites'));
if ($this->activityManager->getRequirePNG()) {
@@ -95,7 +95,7 @@ class FavoriteProvider implements IProvider {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
return $event;
@@ -105,10 +105,10 @@ class FavoriteProvider implements IProvider {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
* @since 11.0.0
*/
- public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
+ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$subject = $this->l->t('You added {file} to your favorites');
if ($this->activityManager->getRequirePNG()) {
@@ -125,7 +125,7 @@ class FavoriteProvider implements IProvider {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
$this->setSubjects($event, $subject);
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php
index f777d11c02e..cb5eb5af1b0 100644
--- a/apps/files/lib/Activity/Provider.php
+++ b/apps/files/lib/Activity/Provider.php
@@ -94,7 +94,7 @@ class Provider implements IProvider {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event, $previousEvent);
- } catch (\InvalidArgumentException $e) {
+ } catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
@@ -114,10 +114,10 @@ class Provider implements IProvider {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
* @since 11.0.0
*/
- public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null) {
+ public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
$parsedParameters = $this->getParameters($event);
if ($event->getSubject() === 'created_by') {
@@ -139,7 +139,7 @@ class Provider implements IProvider {
$subject = $this->l->t('Moved by {user}');
$this->setIcon($event, 'change');
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
if (!isset($parsedParameters['user'])) {
@@ -156,10 +156,10 @@ class Provider implements IProvider {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
* @since 11.0.0
*/
- public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
+ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
$this->fileIsEncrypted = false;
$parsedParameters = $this->getParameters($event);
@@ -253,7 +253,7 @@ class Provider implements IProvider {
$subject = $this->l->t('{user} moved {oldfile} to {newfile}');
$this->setIcon($event, 'change');
} else {
- throw new \InvalidArgumentException();
+ throw new UnknownActivityException();
}
if ($this->fileIsEncrypted) {
@@ -292,9 +292,9 @@ class Provider implements IProvider {
/**
* @param IEvent $event
* @return array
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
*/
- protected function getParameters(IEvent $event) {
+ protected function getParameters(IEvent $event): array {
$parameters = $event->getSubjectParameters();
switch ($event->getSubject()) {
case 'created_self':
@@ -347,9 +347,9 @@ class Provider implements IProvider {
* @param array|string $parameter
* @param IEvent|null $event
* @return array
- * @throws \InvalidArgumentException
+ * @throws UnknownActivityException
*/
- protected function getFile($parameter, ?IEvent $event = null) {
+ protected function getFile($parameter, ?IEvent $event = null): array {
if (is_array($parameter)) {
$path = reset($parameter);
$id = (string)key($parameter);
@@ -358,7 +358,7 @@ class Provider implements IProvider {
$path = $parameter;
$id = $event->getObjectId();
} else {
- throw new \InvalidArgumentException('Could not generate file parameter');
+ throw new UnknownActivityException('Could not generate file parameter');
}
$encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path);
diff --git a/apps/files/tests/Activity/ProviderTest.php b/apps/files/tests/Activity/ProviderTest.php
index 73c726dac3c..7803563a11c 100644
--- a/apps/files/tests/Activity/ProviderTest.php
+++ b/apps/files/tests/Activity/ProviderTest.php
@@ -6,6 +6,7 @@
namespace OCA\Files\Tests\Activity;
use OCA\Files\Activity\Provider;
+use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
@@ -132,7 +133,7 @@ class ProviderTest extends TestCase {
public function testGetFileThrows(): void {
- $this->expectException(\InvalidArgumentException::class);
+ $this->expectException(UnknownActivityException::class);
$provider = $this->getProvider();
self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]);