* @since 8.2.0
*/
public function setAuthor($author) {
- if (!is_string($author) || $author === '' || isset($author[64])) {
- throw new \InvalidArgumentException('The given author user is invalid');
+ if (!is_string($author) || isset($author[64])) {
+ throw new \InvalidArgumentException('The given author user is invalid'. serialize($author));
}
$this->author = (string) $author;
return $this;
* @since 8.2.0
*/
public function setSubject($subject, array $parameters = []) {
- if (!is_string($subject) || $subject === '' || isset($subject[255])) {
+ if (!is_string($subject) || isset($subject[255])) {
throw new \InvalidArgumentException('The given subject is invalid');
}
$this->subject = (string) $subject;
* @since 9.2.0
*/
public function setParsedMessage($message) {
- if (!is_string($message) || $message === '') {
+ if (!is_string($message)) {
throw new \InvalidArgumentException('The given parsed message is invalid');
}
$this->messageParsed = $message;
* @since 9.2.0
*/
public function setRichMessage($message, array $parameters = []) {
- if (!is_string($message) || $message === '') {
+ if (!is_string($message)) {
throw new \InvalidArgumentException('The given parsed message is invalid');
}
$this->messageRich = $message;
* @since 8.2.0
*/
public function setObject($objectType, $objectId, $objectName = '') {
- if (!is_string($objectType) || $objectType === '' || isset($objectType[255])) {
+ if (!is_string($objectType) || isset($objectType[255])) {
throw new \InvalidArgumentException('The given object type is invalid');
}
if (!is_int($objectId)) {
use OCP\Activity\IExtension;
use OCP\Activity\IFilter;
use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
use OCP\Activity\ISetting;
use OCP\IConfig;
use OCP\IRequest;
throw new \InvalidArgumentException('Requested filter does not exist');
}
+ /** @var string[] */
+ protected $providerClasses;
+
+ /** @var IProvider[] */
+ protected $providers;
+
+ /**
+ * @param string $provider Class must implement OCA\Activity\IProvider
+ * @return void
+ */
+ public function registerProvider($provider) {
+ $this->providerClasses[$provider] = false;
+ }
+
+ /**
+ * @return IProvider[]
+ * @throws \InvalidArgumentException
+ */
+ public function getProviders() {
+ foreach ($this->providerClasses as $class => $false) {
+ /** @var IProvider $provider */
+ $provider = \OC::$server->query($class);
+
+ if (!$provider instanceof IProvider) {
+ throw new \InvalidArgumentException('Invalid activity provider registered');
+ }
+
+ $this->providers[] = $provider;
+
+ unset($this->providerClasses[$class]);
+ }
+ return $this->providers;
+ }
+
/** @var string[] */
protected $settingsClasses;
if (!array_key_exists('settings', $array['activity'])) {
$array['activity']['settings'] = [];
}
+ if (!array_key_exists('providers', $array['activity'])) {
+ $array['activity']['providers'] = [];
+ }
if (array_key_exists('types', $array)) {
if (is_array($array['types'])) {
if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
$array['activity']['settings'] = $array['activity']['settings']['setting'];
}
+ if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
+ $array['activity']['providers'] = $array['activity']['providers']['provider'];
+ }
if(!is_null($this->cache)) {
$this->cache->set($fileCacheKey, json_encode($array));
\OC::$server->getActivityManager()->registerSetting($setting);
}
}
+ if (!empty($info['activity']['providers'])) {
+ foreach ($info['activity']['providers'] as $provider) {
+ \OC::$server->getActivityManager()->registerProvider($provider);
+ }
+ }
}
/**
*/
public function getSettings();
+ /**
+ * @param string $provider Class must implement OCA\Activity\IProvider
+ * @return void
+ * @since 9.2.0
+ */
+ public function registerProvider($provider);
+
+ /**
+ * @return IProvider[]
+ * @since 9.2.0
+ */
+ public function getProviders();
+
/**
* @param string $id
* @return ISetting
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 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;
+
+/**
+ * Interface IProvider
+ *
+ * @package OCP\Activity
+ * @since 9.2.0
+ */
+interface IProvider {
+ /**
+ * @param IEvent $event
+ * @param IEvent|null $previousEvent
+ * @return IEvent
+ * @throws \InvalidArgumentException
+ * @since 9.2.0
+ */
+ public function parse(IEvent $event, IEvent $previousEvent = null);
+}