浏览代码

Merge pull request #44886 from nextcloud/techdebt/noid/improved-activity-exceptions

fix(activity): Improved activity exceptions
pull/44915/head
Joas Schilling 1 个月前
父节点
当前提交
2161387ac7
没有帐户链接到提交者的电子邮件

+ 5
- 0
lib/composer/composer/autoload_classmap.php 查看文件

'OCP\\Accounts\\PropertyDoesNotExistException' => $baseDir . '/lib/public/Accounts/PropertyDoesNotExistException.php', 'OCP\\Accounts\\PropertyDoesNotExistException' => $baseDir . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Accounts\\UserUpdatedEvent' => $baseDir . '/lib/public/Accounts/UserUpdatedEvent.php', 'OCP\\Accounts\\UserUpdatedEvent' => $baseDir . '/lib/public/Accounts/UserUpdatedEvent.php',
'OCP\\Activity\\ActivitySettings' => $baseDir . '/lib/public/Activity/ActivitySettings.php', 'OCP\\Activity\\ActivitySettings' => $baseDir . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\Exceptions\\FilterNotFoundException' => $baseDir . '/lib/public/Activity/Exceptions/FilterNotFoundException.php',
'OCP\\Activity\\Exceptions\\IncompleteActivityException' => $baseDir . '/lib/public/Activity/Exceptions/IncompleteActivityException.php',
'OCP\\Activity\\Exceptions\\InvalidValueException' => $baseDir . '/lib/public/Activity/Exceptions/InvalidValueException.php',
'OCP\\Activity\\Exceptions\\SettingNotFoundException' => $baseDir . '/lib/public/Activity/Exceptions/SettingNotFoundException.php',
'OCP\\Activity\\Exceptions\\UnknownActivityException' => $baseDir . '/lib/public/Activity/Exceptions/UnknownActivityException.php',
'OCP\\Activity\\IConsumer' => $baseDir . '/lib/public/Activity/IConsumer.php', 'OCP\\Activity\\IConsumer' => $baseDir . '/lib/public/Activity/IConsumer.php',
'OCP\\Activity\\IEvent' => $baseDir . '/lib/public/Activity/IEvent.php', 'OCP\\Activity\\IEvent' => $baseDir . '/lib/public/Activity/IEvent.php',
'OCP\\Activity\\IEventMerger' => $baseDir . '/lib/public/Activity/IEventMerger.php', 'OCP\\Activity\\IEventMerger' => $baseDir . '/lib/public/Activity/IEventMerger.php',

+ 6
- 0
lib/composer/composer/autoload_static.php 查看文件

'OCP\\Accounts\\PropertyDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Accounts/PropertyDoesNotExistException.php', 'OCP\\Accounts\\PropertyDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Accounts\\UserUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/Accounts/UserUpdatedEvent.php', 'OCP\\Accounts\\UserUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/Accounts/UserUpdatedEvent.php',
'OCP\\Activity\\ActivitySettings' => __DIR__ . '/../../..' . '/lib/public/Activity/ActivitySettings.php', 'OCP\\Activity\\ActivitySettings' => __DIR__ . '/../../..' . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\Exceptions\\FilterNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/FilterNotFoundException.php',
'OCP\\Activity\\Exceptions\\IncompleteActivityException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/IncompleteActivityException.php',
'OCP\\Activity\\Exceptions\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/InvalidValueException.php',
'OCP\\Activity\\Exceptions\\SettingNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/SettingNotFoundException.php',
'OCP\\Activity\\Exceptions\\UnknownActivityException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/UnknownActivityException.php',
'OCP\\Activity\\IConsumer' => __DIR__ . '/../../..' . '/lib/public/Activity/IConsumer.php', 'OCP\\Activity\\IConsumer' => __DIR__ . '/../../..' . '/lib/public/Activity/IConsumer.php',
'OCP\\Activity\\IEvent' => __DIR__ . '/../../..' . '/lib/public/Activity/IEvent.php', 'OCP\\Activity\\IEvent' => __DIR__ . '/../../..' . '/lib/public/Activity/IEvent.php',
'OCP\\Activity\\IEventMerger' => __DIR__ . '/../../..' . '/lib/public/Activity/IEventMerger.php', 'OCP\\Activity\\IEventMerger' => __DIR__ . '/../../..' . '/lib/public/Activity/IEventMerger.php',
'OC\\Core\\Command\\User\\AuthTokens\\Add' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/Add.php', 'OC\\Core\\Command\\User\\AuthTokens\\Add' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/Add.php',
'OC\\Core\\Command\\User\\AuthTokens\\Delete' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/Delete.php', 'OC\\Core\\Command\\User\\AuthTokens\\Delete' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/Delete.php',
'OC\\Core\\Command\\User\\AuthTokens\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/ListCommand.php', 'OC\\Core\\Command\\User\\AuthTokens\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/User/AuthTokens/ListCommand.php',
'OC\\Core\\Command\\User\\ClearGeneratedAvatarCacheCommand' => __DIR__ . '/../../..' . '/core/Command/User/ClearGeneratedAvatarCacheCommand.php',
'OC\\Core\\Command\\User\\Delete' => __DIR__ . '/../../..' . '/core/Command/User/Delete.php', 'OC\\Core\\Command\\User\\Delete' => __DIR__ . '/../../..' . '/core/Command/User/Delete.php',
'OC\\Core\\Command\\User\\Disable' => __DIR__ . '/../../..' . '/core/Command/User/Disable.php', 'OC\\Core\\Command\\User\\Disable' => __DIR__ . '/../../..' . '/core/Command/User/Disable.php',
'OC\\Core\\Command\\User\\Enable' => __DIR__ . '/../../..' . '/core/Command/User/Enable.php', 'OC\\Core\\Command\\User\\Enable' => __DIR__ . '/../../..' . '/core/Command/User/Enable.php',

+ 40
- 94
lib/private/Activity/Event.php 查看文件

*/ */
namespace OC\Activity; namespace OC\Activity;


use OCP\Activity\Exceptions\InvalidValueException;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\RichObjectStrings\InvalidObjectExeption; use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator; use OCP\RichObjectStrings\IValidator;
} }


/** /**
* Set the app of the activity
*
* @param string $app
* @return IEvent
* @throws \InvalidArgumentException if the app id is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setApp(string $app): IEvent { public function setApp(string $app): IEvent {
if ($app === '' || isset($app[32])) { if ($app === '' || isset($app[32])) {
throw new \InvalidArgumentException('The given app is invalid');
throw new InvalidValueException('app');
} }
$this->app = $app; $this->app = $app;
return $this; return $this;
} }


/** /**
* Set the type of the activity
*
* @param string $type
* @return IEvent
* @throws \InvalidArgumentException if the type is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setType(string $type): IEvent { public function setType(string $type): IEvent {
if ($type === '' || isset($type[255])) { if ($type === '' || isset($type[255])) {
throw new \InvalidArgumentException('The given type is invalid');
throw new InvalidValueException('type');
} }
$this->type = $type; $this->type = $type;
return $this; return $this;
} }


/** /**
* Set the affected user of the activity
*
* @param string $affectedUser
* @return IEvent
* @throws \InvalidArgumentException if the affected user is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setAffectedUser(string $affectedUser): IEvent { public function setAffectedUser(string $affectedUser): IEvent {
if ($affectedUser === '' || isset($affectedUser[64])) { if ($affectedUser === '' || isset($affectedUser[64])) {
throw new \InvalidArgumentException('The given affected user is invalid');
throw new InvalidValueException('affectedUser');
} }
$this->affectedUser = $affectedUser; $this->affectedUser = $affectedUser;
return $this; return $this;
} }


/** /**
* Set the author of the activity
*
* @param string $author
* @return IEvent
* @throws \InvalidArgumentException if the author is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setAuthor(string $author): IEvent { public function setAuthor(string $author): IEvent {
if (isset($author[64])) { if (isset($author[64])) {
throw new \InvalidArgumentException('The given author user is invalid');
throw new InvalidValueException('author');
} }
$this->author = $author; $this->author = $author;
return $this; return $this;
} }


/** /**
* Set the timestamp of the activity
*
* @param int $timestamp
* @return IEvent
* @throws \InvalidArgumentException if the timestamp is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setTimestamp(int $timestamp): IEvent { public function setTimestamp(int $timestamp): IEvent {
if ($timestamp < 0) {
throw new InvalidValueException('timestamp');
}
$this->timestamp = $timestamp; $this->timestamp = $timestamp;
return $this; return $this;
} }
} }


/** /**
* Set the subject of the activity
*
* @param string $subject
* @param array $parameters
* @return IEvent
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setSubject(string $subject, array $parameters = []): IEvent { public function setSubject(string $subject, array $parameters = []): IEvent {
if (isset($subject[255])) { if (isset($subject[255])) {
throw new \InvalidArgumentException('The given subject is invalid');
throw new InvalidValueException('subject');
} }
$this->subject = $subject; $this->subject = $subject;
$this->subjectParameters = $parameters; $this->subjectParameters = $parameters;
} }


/** /**
* @param string $subject
* @return $this
* @throws \InvalidArgumentException if the subject is invalid
* @since 11.0.0
* {@inheritDoc}
*/ */
public function setParsedSubject(string $subject): IEvent { public function setParsedSubject(string $subject): IEvent {
if ($subject === '') { if ($subject === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
throw new InvalidValueException('parsedSubject');
} }
$this->subjectParsed = $subject; $this->subjectParsed = $subject;
return $this; return $this;
} }


/** /**
* @param string $subject
* @param array $parameters
* @return $this
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 11.0.0
* {@inheritDoc}
*/ */
public function setRichSubject(string $subject, array $parameters = []): IEvent { public function setRichSubject(string $subject, array $parameters = []): IEvent {
if ($subject === '') { if ($subject === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
throw new InvalidValueException('richSubject');
} }
$this->subjectRich = $subject; $this->subjectRich = $subject;
$this->subjectRichParameters = $parameters; $this->subjectRichParameters = $parameters;


if ($this->subjectParsed === '') { if ($this->subjectParsed === '') {
$this->subjectParsed = $this->richToParsed($subject, $parameters);
try {
$this->subjectParsed = $this->richToParsed($subject, $parameters);
} catch (\InvalidArgumentException $e) {
throw new InvalidValueException('richSubjectParameters', $e);
}
} }


return $this; return $this;
} }


/** /**
* Set the message of the activity
*
* @param string $message
* @param array $parameters
* @return IEvent
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setMessage(string $message, array $parameters = []): IEvent { public function setMessage(string $message, array $parameters = []): IEvent {
if (isset($message[255])) { if (isset($message[255])) {
throw new \InvalidArgumentException('The given message is invalid');
throw new InvalidValueException('message');
} }
$this->message = $message; $this->message = $message;
$this->messageParameters = $parameters; $this->messageParameters = $parameters;
} }


/** /**
* @param string $message
* @return $this
* @throws \InvalidArgumentException if the message is invalid
* @since 11.0.0
* {@inheritDoc}
*/ */
public function setParsedMessage(string $message): IEvent { public function setParsedMessage(string $message): IEvent {
$this->messageParsed = $message; $this->messageParsed = $message;
} }


/** /**
* @param string $message
* @param array $parameters
* @return $this
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 11.0.0
* {@inheritDoc}
*/ */
public function setRichMessage(string $message, array $parameters = []): IEvent { public function setRichMessage(string $message, array $parameters = []): IEvent {
$this->messageRich = $message; $this->messageRich = $message;
$this->messageRichParameters = $parameters; $this->messageRichParameters = $parameters;


if ($this->messageParsed === '') { if ($this->messageParsed === '') {
$this->messageParsed = $this->richToParsed($message, $parameters);
try {
$this->messageParsed = $this->richToParsed($message, $parameters);
} catch (\InvalidArgumentException $e) {
throw new InvalidValueException('richMessageParameters', $e);
}
} }


return $this; return $this;
} }


/** /**
* Set the object of the activity
*
* @param string $objectType
* @param int $objectId
* @param string $objectName
* @return IEvent
* @throws \InvalidArgumentException if the object is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setObject(string $objectType, int $objectId, string $objectName = ''): IEvent { public function setObject(string $objectType, int $objectId, string $objectName = ''): IEvent {
if (isset($objectType[255])) { if (isset($objectType[255])) {
throw new \InvalidArgumentException('The given object type is invalid');
throw new InvalidValueException('objectType');
} }
if (isset($objectName[4000])) { if (isset($objectName[4000])) {
throw new \InvalidArgumentException('The given object name is invalid');
throw new InvalidValueException('objectName');
} }
$this->objectType = $objectType; $this->objectType = $objectType;
$this->objectId = $objectId; $this->objectId = $objectId;
} }


/** /**
* Set the link of the activity
*
* @param string $link
* @return IEvent
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
* {@inheritDoc}
*/ */
public function setLink(string $link): IEvent { public function setLink(string $link): IEvent {
if (isset($link[4000])) { if (isset($link[4000])) {
throw new \InvalidArgumentException('The given link is invalid');
throw new InvalidValueException('link');
} }
$this->link = $link; $this->link = $link;
return $this; return $this;
} }


/** /**
* @param string $icon
* @return $this
* @throws \InvalidArgumentException if the icon is invalid
* @since 11.0.0
* {@inheritDoc}
*/ */
public function setIcon(string $icon): IEvent { public function setIcon(string $icon): IEvent {
if (isset($icon[4000])) { if (isset($icon[4000])) {
throw new \InvalidArgumentException('The given icon is invalid');
throw new InvalidValueException('icon');
} }
$this->icon = $icon; $this->icon = $icon;
return $this; return $this;

+ 9
- 25
lib/private/Activity/Manager.php 查看文件

namespace OC\Activity; namespace OC\Activity;


use OCP\Activity\ActivitySettings; use OCP\Activity\ActivitySettings;
use OCP\Activity\Exceptions\FilterNotFoundException;
use OCP\Activity\Exceptions\IncompleteActivityException;
use OCP\Activity\Exceptions\SettingNotFoundException;
use OCP\Activity\IConsumer; use OCP\Activity\IConsumer;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IFilter; use OCP\Activity\IFilter;
} }


/** /**
* Publish an event to the activity consumers
*
* Make sure to call at least the following methods before sending an Event:
* - setApp()
* - setType()
* - setAffectedUser()
* - setSubject()
*
* @param IEvent $event
* @throws \BadMethodCallException if required values have not been set
* {@inheritDoc}
*/ */
public function publish(IEvent $event): void { public function publish(IEvent $event): void {
if ($event->getAuthor() === '') { if ($event->getAuthor() === '') {
} }


if (!$event->isValid()) { if (!$event->isValid()) {
throw new \BadMethodCallException('The given event is invalid');
throw new IncompleteActivityException('The given event is invalid');
} }


foreach ($this->getConsumers() as $c) { foreach ($this->getConsumers() as $c) {
} }


/** /**
* @param string $id
* @return IFilter
* @throws \InvalidArgumentException when the filter was not found
* @since 11.0.0
* {@inheritDoc}
*/ */
public function getFilterById(string $id): IFilter { public function getFilterById(string $id): IFilter {
$filters = $this->getFilters(); $filters = $this->getFilters();
return $filters[$id]; return $filters[$id];
} }


throw new \InvalidArgumentException('Requested filter does not exist');
throw new FilterNotFoundException($id);
} }


/** @var string[] */ /** @var string[] */
} }


/** /**
* @param string $id
* @return ActivitySettings
* @throws \InvalidArgumentException when the setting was not found
* @since 11.0.0
* {@inheritDoc}
*/ */
public function getSettingById(string $id): ActivitySettings { public function getSettingById(string $id): ActivitySettings {
$settings = $this->getSettings(); $settings = $this->getSettings();
return $settings[$id]; return $settings[$id];
} }


throw new \InvalidArgumentException('Requested setting does not exist');
throw new SettingNotFoundException($id);
} }




* Set the user we need to use * Set the user we need to use
* *
* @param string|null $currentUserId * @param string|null $currentUserId
* @throws \UnexpectedValueException If the user is invalid
*/ */
public function setCurrentUserId(?string $currentUserId = null): void { public function setCurrentUserId(?string $currentUserId = null): void {
if (!is_string($currentUserId) && $currentUserId !== null) {
throw new \UnexpectedValueException('The given current user is invalid');
}
$this->currentUserId = $currentUserId; $this->currentUserId = $currentUserId;
} }



+ 48
- 0
lib/public/Activity/Exceptions/FilterNotFoundException.php 查看文件

<?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\Activity\Exceptions;

/**
* @since 30.0.0
*/
class FilterNotFoundException extends \InvalidArgumentException {
/**
* @since 30.0.0
*/
public function __construct(
protected string $filter,
) {
parent::__construct('Filter ' . $filter . ' not found');
}

/**
* @since 30.0.0
*/
public function getFilterId(): string {
return $this->filter;
}
}

+ 43
- 0
lib/public/Activity/Exceptions/IncompleteActivityException.php 查看文件

<?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\Activity\Exceptions;

/**
* Thrown when {@see \OCP\Notification\IManager::notify()} is called with a notification
* that does not have all required fields set:
*
* - app
* - type
* - affectedUser
* - subject
* - objectType
* - objectId
*
* @since 30.0.0
*/
class IncompleteActivityException extends \BadMethodCallException {
}

+ 49
- 0
lib/public/Activity/Exceptions/InvalidValueException.php 查看文件

<?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\Activity\Exceptions;

/**
* @since 30.0.0
*/
class InvalidValueException extends \InvalidArgumentException {
/**
* @since 30.0.0
*/
public function __construct(
protected string $field,
?\Throwable $previous = null,
) {
parent::__construct('Value provided for ' . $field . ' is not valid', previous: $previous);
}

/**
* @since 30.0.0
*/
public function getFieldIdentifier(): string {
return $this->field;
}
}

+ 48
- 0
lib/public/Activity/Exceptions/SettingNotFoundException.php 查看文件

<?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\Activity\Exceptions;

/**
* @since 30.0.0
*/
class SettingNotFoundException extends \InvalidArgumentException {
/**
* @since 30.0.0
*/
public function __construct(
protected string $setting,
) {
parent::__construct('Setting ' . $setting . ' not found');
}

/**
* @since 30.0.0
*/
public function getSettingId(): string {
return $this->setting;
}
}

+ 33
- 0
lib/public/Activity/Exceptions/UnknownActivityException.php 查看文件

<?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\Activity\Exceptions;

/**
* @since 30.0.0
*/
class UnknownActivityException extends \InvalidArgumentException {
}

+ 33
- 17
lib/public/Activity/IEvent.php 查看文件



namespace OCP\Activity; namespace OCP\Activity;


use OCP\Activity\Exceptions\InvalidValueException;

/** /**
* Interface IEvent * Interface IEvent
* *
* *
* @param string $app * @param string $app
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the app id is invalid
* @throws InvalidValueException if the app id is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setApp(string $app): self; public function setApp(string $app): self;


* *
* @param string $type * @param string $type
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the type is invalid
* @throws InvalidValueException if the type is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setType(string $type): self; public function setType(string $type): self;


/** /**
* Set the affected user of the activity * Set the affected user of the activity
* *
* @param string $user
* @param string $affectedUser
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the affected user is invalid
* @throws InvalidValueException if the affected user is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setAffectedUser(string $user): self;
public function setAffectedUser(string $affectedUser): self;


/** /**
* Set the author of the activity * Set the author of the activity
* *
* @param string $author * @param string $author
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the author is invalid
* @throws InvalidValueException if the author is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setAuthor(string $author): self; public function setAuthor(string $author): self;


* *
* @param int $timestamp * @param int $timestamp
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the timestamp is invalid
* @throws InvalidValueException if the timestamp is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setTimestamp(int $timestamp): self; public function setTimestamp(int $timestamp): self;


* @param string $subject * @param string $subject
* @param array $parameters * @param array $parameters
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @throws InvalidValueException if the subject or parameters are invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setSubject(string $subject, array $parameters = []): self; public function setSubject(string $subject, array $parameters = []): self;


* *
* @param string $subject * @param string $subject
* @return $this * @return $this
* @throws \InvalidArgumentException if the subject is invalid
* @throws InvalidValueException if the subject is invalid
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setParsedSubject(string $subject): self; public function setParsedSubject(string $subject): self;


* @param string $subject * @param string $subject
* @param array $parameters * @param array $parameters
* @return $this * @return $this
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @throws InvalidValueException if the subject or parameters are invalid
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setRichSubject(string $subject, array $parameters = []): self; public function setRichSubject(string $subject, array $parameters = []): self;


* @param string $message * @param string $message
* @param array $parameters * @param array $parameters
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the message or parameters are invalid
* @throws InvalidValueException if the message or parameters are invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setMessage(string $message, array $parameters = []): self; public function setMessage(string $message, array $parameters = []): self;


* *
* @param string $message * @param string $message
* @return $this * @return $this
* @throws \InvalidArgumentException if the message is invalid
* @throws InvalidValueException if the message is invalid
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setParsedMessage(string $message): self; public function setParsedMessage(string $message): self;


* @return $this * @return $this
* @throws \InvalidArgumentException if the message or parameters are invalid * @throws \InvalidArgumentException if the message or parameters are invalid
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setRichMessage(string $message, array $parameters = []): self; public function setRichMessage(string $message, array $parameters = []): self;


* @param int $objectId * @param int $objectId
* @param string $objectName * @param string $objectName
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the object is invalid
* @throws InvalidValueException if the object is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setObject(string $objectType, int $objectId, string $objectName = ''): self; public function setObject(string $objectType, int $objectId, string $objectName = ''): self;


* *
* @param string $link * @param string $link
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException if the link is invalid
* @throws InvalidValueException if the link is invalid
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setLink(string $link): self; public function setLink(string $link): self;


/** /**
* @param string $icon * @param string $icon
* @return $this * @return $this
* @throws \InvalidArgumentException if the icon is invalid
* @throws InvalidValueException if the icon is invalid
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see InvalidValueException} instead of \InvalidArgumentException
*/ */
public function setIcon(string $icon): self; public function setIcon(string $icon): self;


public function isValidParsed(): bool; public function isValidParsed(): bool;


/** /**
* Set whether or not a notification should be automatically generated for this activity.
* Set whether a notification should be automatically generated for this activity.
* *
* Set this to `false` if the app already generates a notification for the event. * Set this to `false` if the app already generates a notification for the event.
* *
public function setGenerateNotification(bool $generate): self; public function setGenerateNotification(bool $generate): self;


/** /**
* whether or not a notification should be automatically generated for this activity.
* Whether a notification should be automatically generated for this activity.
* *
* @return bool * @return bool
* @since 20.0.0 * @since 20.0.0

+ 10
- 4
lib/public/Activity/IManager.php 查看文件

*/ */
namespace OCP\Activity; namespace OCP\Activity;


use OCP\Activity\Exceptions\FilterNotFoundException;
use OCP\Activity\Exceptions\IncompleteActivityException;
use OCP\Activity\Exceptions\SettingNotFoundException;

/** /**
* Interface IManager * Interface IManager
* *
* - setObject() * - setObject()
* *
* @param IEvent $event * @param IEvent $event
* @throws \BadMethodCallException if required values have not been set
* @throws IncompleteActivityException if required values have not been set
* @since 8.2.0 * @since 8.2.0
* @since 30.0.0 throws {@see IncompleteActivityException} instead of \BadMethodCallException
*/ */
public function publish(IEvent $event): void; public function publish(IEvent $event): void;


/** /**
* @param string $id * @param string $id
* @return IFilter * @return IFilter
* @throws \InvalidArgumentException when the filter was not found
* @throws FilterNotFoundException when the filter was not found
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see FilterNotFoundException} instead of \InvalidArgumentException
*/ */
public function getFilterById(string $id): IFilter; public function getFilterById(string $id): IFilter;


/** /**
* @param string $id * @param string $id
* @return ActivitySettings * @return ActivitySettings
* @throws \InvalidArgumentException when the setting was not found
* @throws SettingNotFoundException when the setting was not found
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 throws {@see SettingNotFoundException} instead of \InvalidArgumentException
*/ */
public function getSettingById(string $id): ActivitySettings; public function getSettingById(string $id): ActivitySettings;


* Set the user we need to use * Set the user we need to use
* *
* @param string|null $currentUserId * @param string|null $currentUserId
* @throws \UnexpectedValueException If the user is invalid
* @since 9.0.1 * @since 9.0.1
*/ */
public function setCurrentUserId(?string $currentUserId = null): void; public function setCurrentUserId(?string $currentUserId = null): void;

+ 6
- 1
lib/public/Activity/IProvider.php 查看文件

*/ */
namespace OCP\Activity; namespace OCP\Activity;


use OCP\Activity\Exceptions\UnknownActivityException;

/** /**
* Interface IProvider * Interface IProvider
* *
* To do so, simply use setChildEvent($previousEvent) after setting the * To do so, simply use setChildEvent($previousEvent) after setting the
* combined subject on the current event. * combined subject on the current event.
* @return IEvent * @return IEvent
* @throws \InvalidArgumentException Should be thrown if your provider does not know this event
* @throws UnknownActivityException Should be thrown if your provider does not know this event
* @since 11.0.0 * @since 11.0.0
* @since 30.0.0 Providers should throw {@see UnknownActivityException} instead of \InvalidArgumentException
* when they did not handle the event. Throwing \InvalidArgumentException directly is deprecated and will
* be logged as an error in Nextcloud 39.
*/ */
public function parse($language, IEvent $event, ?IEvent $previousEvent = null); public function parse($language, IEvent $event, ?IEvent $previousEvent = null);
} }

+ 5
- 4
tests/lib/Activity/ManagerTest.php 查看文件



namespace Test\Activity; namespace Test\Activity;


use OCP\Activity\Exceptions\IncompleteActivityException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;




public function testPublishExceptionNoApp() { public function testPublishExceptionNoApp() {
$this->expectException(\BadMethodCallException::class);
$this->expectException(IncompleteActivityException::class);


$event = $this->activityManager->generateEvent(); $event = $this->activityManager->generateEvent();
$this->activityManager->publish($event); $this->activityManager->publish($event);




public function testPublishExceptionNoType() { public function testPublishExceptionNoType() {
$this->expectException(\BadMethodCallException::class);
$this->expectException(IncompleteActivityException::class);


$event = $this->activityManager->generateEvent(); $event = $this->activityManager->generateEvent();
$event->setApp('test'); $event->setApp('test');




public function testPublishExceptionNoAffectedUser() { public function testPublishExceptionNoAffectedUser() {
$this->expectException(\BadMethodCallException::class);
$this->expectException(IncompleteActivityException::class);


$event = $this->activityManager->generateEvent(); $event = $this->activityManager->generateEvent();
$event->setApp('test') $event->setApp('test')




public function testPublishExceptionNoSubject() { public function testPublishExceptionNoSubject() {
$this->expectException(\BadMethodCallException::class);
$this->expectException(IncompleteActivityException::class);


$event = $this->activityManager->generateEvent(); $event = $this->activityManager->generateEvent();
$event->setApp('test') $event->setApp('test')

正在加载...
取消
保存