diff options
Diffstat (limited to 'lib/private/Collaboration/Resources/Manager.php')
-rw-r--r-- | lib/private/Collaboration/Resources/Manager.php | 99 |
1 files changed, 20 insertions, 79 deletions
diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 97213c45669..8d1e4b13287 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -3,29 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com> - * - * @author Daniel Kesselberg <mail@danielkesselberg.de> - * @author Joas Schilling <coding@schilljs.com> - * @author Julius Härtl <jus@bitgrid.net> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OC\Collaboration\Resources; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; @@ -38,34 +18,25 @@ use OCP\Collaboration\Resources\IResource; use OCP\Collaboration\Resources\ResourceException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUser; +use Psr\Log\LoggerInterface; class Manager implements IManager { public const TABLE_COLLECTIONS = 'collres_collections'; public const TABLE_RESOURCES = 'collres_resources'; public const TABLE_ACCESS_CACHE = 'collres_accesscache'; - /** @var IDBConnection */ - protected $connection; - /** @var IProviderManager */ - protected $providerManager; - /** @var ILogger */ - protected $logger; - /** @var string[] */ - protected $providers = []; - + protected array $providers = []; - public function __construct(IDBConnection $connection, IProviderManager $providerManager, ILogger $logger) { - $this->connection = $connection; - $this->providerManager = $providerManager; - $this->logger = $logger; + public function __construct( + protected IDBConnection $connection, + protected IProviderManager $providerManager, + protected LoggerInterface $logger, + ) { } /** - * @param int $id - * @return ICollection * @throws CollectionException when the collection could not be found * @since 16.0.0 */ @@ -82,13 +53,10 @@ class Manager implements IManager { throw new CollectionException('Collection not found'); } - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']); + return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name']); } /** - * @param int $id - * @param IUser|null $user - * @return ICollection * @throws CollectionException when the collection could not be found * @since 16.0.0 */ @@ -114,25 +82,21 @@ class Manager implements IManager { throw new CollectionException('Collection not found'); } - $access = $row['access'] === null ? null : (bool) $row['access']; + $access = $row['access'] === null ? null : (bool)$row['access']; if ($user instanceof IUser) { - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); + return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); } - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); + return new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); } /** - * @param IUser $user - * @param string $filter - * @param int $limit - * @param int $start * @return ICollection[] * @since 16.0.0 */ public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array { $query = $this->connection->getQueryBuilder(); - $userId = $user instanceof IUser ? $user->getUID() : ''; + $userId = $user->getUID(); $query->select('c.*', 'a.access') ->from(self::TABLE_COLLECTIONS, 'c') @@ -149,7 +113,7 @@ class Manager implements IManager { ->setFirstResult($start); if ($filter !== '') { - $query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%'))); + $query->andWhere($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%'))); } $result = $query->execute(); @@ -158,7 +122,7 @@ class Manager implements IManager { $foundResults = 0; while ($row = $result->fetch()) { $foundResults++; - $access = $row['access'] === null ? null : (bool) $row['access']; + $access = $row['access'] === null ? null : (bool)$row['access']; $collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); if ($collection->canAccess($user)) { $collections[] = $collection; @@ -174,8 +138,6 @@ class Manager implements IManager { } /** - * @param string $name - * @return ICollection * @since 16.0.0 */ public function newCollection(string $name): ICollection { @@ -190,9 +152,6 @@ class Manager implements IManager { } /** - * @param string $type - * @param string $id - * @return IResource * @since 16.0.0 */ public function createResource(string $type, string $id): IResource { @@ -200,10 +159,6 @@ class Manager implements IManager { } /** - * @param string $type - * @param string $id - * @param IUser|null $user - * @return IResource * @throws ResourceException * @since 16.0.0 */ @@ -231,7 +186,7 @@ class Manager implements IManager { throw new ResourceException('Resource not found'); } - $access = $row['access'] === null ? null : (bool) $row['access']; + $access = $row['access'] === null ? null : (bool)$row['access']; if ($user instanceof IUser) { return new Resource($this, $this->connection, $type, $id, $user, $access); } @@ -240,8 +195,6 @@ class Manager implements IManager { } /** - * @param ICollection $collection - * @param IUser|null $user * @return IResource[] * @since 16.0.0 */ @@ -264,7 +217,7 @@ class Manager implements IManager { $resources = []; $result = $query->execute(); while ($row = $result->fetch()) { - $access = $row['access'] === null ? null : (bool) $row['access']; + $access = $row['access'] === null ? null : (bool)$row['access']; $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access); } $result->closeCursor(); @@ -275,8 +228,6 @@ class Manager implements IManager { /** * Get the rich object data of a resource * - * @param IResource $resource - * @return array * @since 16.0.0 */ public function getResourceRichObject(IResource $resource): array { @@ -295,9 +246,6 @@ class Manager implements IManager { /** * Can a user/guest access the collection * - * @param IResource $resource - * @param IUser|null $user - * @return bool * @since 16.0.0 */ public function canAccessResource(IResource $resource, ?IUser $user): bool { @@ -326,9 +274,6 @@ class Manager implements IManager { /** * Can a user/guest access the collection * - * @param ICollection $collection - * @param IUser|null $user - * @return bool * @since 16.0.0 */ public function canAccessCollection(ICollection $collection, ?IUser $user): bool { @@ -366,7 +311,7 @@ class Manager implements IManager { $hasAccess = null; $result = $query->execute(); if ($row = $result->fetch()) { - $hasAccess = (bool) $row['access']; + $hasAccess = (bool)$row['access']; } $result->closeCursor(); @@ -386,7 +331,7 @@ class Manager implements IManager { $hasAccess = null; $result = $query->execute(); if ($row = $result->fetch()) { - $hasAccess = (bool) $row['access']; + $hasAccess = (bool)$row['access']; } $result->closeCursor(); @@ -506,9 +451,6 @@ class Manager implements IManager { $query->execute(); } - /** - * @param string $provider - */ public function registerResourceProvider(string $provider): void { $this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]); $this->providerManager->registerResourceProvider($provider); @@ -517,7 +459,6 @@ class Manager implements IManager { /** * Get the resource type of the provider * - * @return string * @since 16.0.0 */ public function getType(): string { |