make it possible to register plugins and kick out the circle one
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
4a96e22258
commit
f7713e5f3f
5 changed files with 32 additions and 62 deletions
|
@ -165,6 +165,9 @@ class InfoParser {
|
|||
if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
|
||||
$array['activity']['providers'] = $array['activity']['providers']['provider'];
|
||||
}
|
||||
if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])) {
|
||||
$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
|
||||
}
|
||||
|
||||
if(!is_null($this->cache)) {
|
||||
$this->cache->set($fileCacheKey, json_encode($array));
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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 OC\Collaboration\Collaborators;
|
||||
|
||||
|
||||
use OCA\Circles\Api\Sharees;
|
||||
use OCP\Collaboration\Collaborators\ISearchPlugin;
|
||||
use OCP\Collaboration\Collaborators\ISearchResult;
|
||||
use OCP\Collaboration\Collaborators\SearchResultType;
|
||||
|
||||
class CirclePlugin implements ISearchPlugin {
|
||||
|
||||
public function search($search, $limit, $offset, ISearchResult $searchResult) {
|
||||
$result = ['wide' => [], 'exact' => []];
|
||||
|
||||
if(\OC_App::isEnabled('circles')) {
|
||||
$circles = Sharees::search($search);
|
||||
if (array_key_exists('circles', $circles['exact'])) {
|
||||
$result['exact'] = $circles['exact']['circles'];
|
||||
}
|
||||
if (array_key_exists('circles', $circles)) {
|
||||
$result['wide'] = $circles['circles'];
|
||||
}
|
||||
|
||||
$type = new SearchResultType('circles');
|
||||
$searchResult->addResultSet($type, $result['wide'], $result['exact']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -34,6 +34,13 @@ class Search implements ISearch {
|
|||
/** @var IContainer */
|
||||
private $c;
|
||||
|
||||
protected $pluginList = [
|
||||
Share::SHARE_TYPE_USER => UserPlugin::class,
|
||||
Share::SHARE_TYPE_GROUP => GroupPlugin::class,
|
||||
Share::SHARE_TYPE_EMAIL => MailPlugin::class,
|
||||
Share::SHARE_TYPE_REMOTE => RemotePlugin::class,
|
||||
];
|
||||
|
||||
public function __construct(IContainer $c) {
|
||||
$this->c = $c;
|
||||
}
|
||||
|
@ -41,23 +48,15 @@ class Search implements ISearch {
|
|||
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
|
||||
$hasMoreResults = false;
|
||||
|
||||
$pluginList = [
|
||||
Share::SHARE_TYPE_USER => UserPlugin::class,
|
||||
Share::SHARE_TYPE_GROUP => GroupPlugin::class,
|
||||
Share::SHARE_TYPE_CIRCLE => CirclePlugin::class,
|
||||
Share::SHARE_TYPE_EMAIL => MailPlugin::class,
|
||||
Share::SHARE_TYPE_REMOTE => RemotePlugin::class,
|
||||
];
|
||||
|
||||
/** @var ISearchResult $searchResult */
|
||||
$searchResult = $this->c->resolve(SearchResult::class);
|
||||
|
||||
foreach ($shareTypes as $type) {
|
||||
if(!isset($pluginList[$type])) {
|
||||
if(!isset($this->pluginList[$type])) {
|
||||
continue;
|
||||
}
|
||||
/** @var ISearchPlugin $searchPlugin */
|
||||
$searchPlugin = $this->c->resolve($pluginList[$type]);
|
||||
$searchPlugin = $this->c->resolve($this->pluginList[$type]);
|
||||
$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
|
||||
}
|
||||
|
||||
|
@ -82,4 +81,12 @@ class Search implements ISearch {
|
|||
|
||||
return [$searchResult->asArray(), $hasMoreResults];
|
||||
}
|
||||
|
||||
public function registerPlugin(array $pluginInfo) {
|
||||
$shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
|
||||
if($shareType === null) {
|
||||
throw new \InvalidArgumentException('Provided ShareType is invalid');
|
||||
}
|
||||
$this->pluginList[$shareType] = $pluginInfo['class'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,11 @@ class OC_App {
|
|||
\OC::$server->getActivityManager()->registerProvider($provider);
|
||||
}
|
||||
}
|
||||
if (!empty($info['collaboration']['collaborators']['searchPlugins'])) {
|
||||
foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) {
|
||||
\OC::$server->getCollaboratorSearch()->registerPlugin($plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,4 +40,11 @@ interface ISearch {
|
|||
* @since 13.0.0
|
||||
*/
|
||||
public function search($search, array $shareTypes, $lookup, $limit, $offset);
|
||||
|
||||
/**
|
||||
* @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and
|
||||
* 'class' with the class name of the plugin
|
||||
* @since 13.0.0
|
||||
*/
|
||||
public function registerPlugin(array $pluginInfo);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue