diff options
Diffstat (limited to 'apps/files_external/lib/Service/StoragesService.php')
-rw-r--r-- | apps/files_external/lib/Service/StoragesService.php | 92 |
1 files changed, 25 insertions, 67 deletions
diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index 489192dbdc2..a12a8fc245a 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -1,37 +1,13 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jesús Macias <jmacias@solidgear.es> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Stefan Weil <sw@weilnetz.de> - * @author szaimen <szaimen@e.mail.de> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\Files_External\Service; +use OC\Files\Cache\Storage; use OC\Files\Filesystem; use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Auth\InvalidAuth; @@ -44,44 +20,27 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\StorageNotAvailableException; -use OCP\ILogger; +use OCP\Server; +use OCP\Util; +use Psr\Log\LoggerInterface; /** * Service class to manage external storage */ abstract class StoragesService { - /** @var BackendService */ - protected $backendService; - - /** - * @var DBConfigService - */ - protected $dbConfig; - - /** - * @var IUserMountCache - */ - protected $userMountCache; - - protected IEventDispatcher $eventDispatcher; - /** * @param BackendService $backendService - * @param DBConfigService $dbConfigService + * @param DBConfigService $dbConfig * @param IUserMountCache $userMountCache * @param IEventDispatcher $eventDispatcher */ public function __construct( - BackendService $backendService, - DBConfigService $dbConfigService, - IUserMountCache $userMountCache, - IEventDispatcher $eventDispatcher + protected BackendService $backendService, + protected DBConfigService $dbConfig, + protected IUserMountCache $userMountCache, + protected IEventDispatcher $eventDispatcher, ) { - $this->backendService = $backendService; - $this->dbConfig = $dbConfigService; - $this->userMountCache = $userMountCache; - $this->eventDispatcher = $eventDispatcher; } protected function readDBConfig() { @@ -119,17 +78,15 @@ abstract class StoragesService { return $config; } catch (\UnexpectedValueException $e) { // don't die if a storage backend doesn't exist - \OC::$server->getLogger()->logException($e, [ - 'message' => 'Could not load storage.', - 'level' => ILogger::ERROR, + Server::get(LoggerInterface::class)->error('Could not load storage.', [ 'app' => 'files_external', + 'exception' => $e, ]); return null; } catch (\InvalidArgumentException $e) { - \OC::$server->getLogger()->logException($e, [ - 'message' => 'Could not load storage.', - 'level' => ILogger::ERROR, + Server::get(LoggerInterface::class)->error('Could not load storage.', [ 'app' => 'files_external', + 'exception' => $e, ]); return null; } @@ -162,7 +119,7 @@ abstract class StoragesService { * @return StorageConfig * @throws NotFoundException if the storage with the given id was not found */ - public function getStorage($id) { + public function getStorage(int $id) { $mount = $this->dbConfig->getMountById($id); if (!is_array($mount)) { @@ -231,7 +188,7 @@ abstract class StoragesService { /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return int BackendService::VISIBILITY_* constants */ abstract public function getVisibilityType(); @@ -310,7 +267,7 @@ abstract class StoragesService { $mountOptions = null, $applicableUsers = null, $applicableGroups = null, - $priority = null + $priority = null, ) { $backend = $this->backendService->getBackend($backendIdentifier); if (!$backend) { @@ -345,14 +302,14 @@ abstract class StoragesService { * Triggers the given hook signal for all the applicables given * * @param string $signal signal - * @param string $mountPoint hook mount pount param + * @param string $mountPoint hook mount point param * @param string $mountType hook mount type param * @param array $applicableArray array of applicable users/groups for which to trigger the hook */ protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void { $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null)); foreach ($applicableArray as $applicable) { - \OCP\Util::emitHook( + Util::emitHook( Filesystem::CLASSNAME, $signal, [ @@ -478,7 +435,7 @@ abstract class StoragesService { * * @throws NotFoundException if no storage was found with the given id */ - public function removeStorage($id) { + public function removeStorage(int $id) { $existingMount = $this->dbConfig->getMountById($id); if (!is_array($existingMount)) { @@ -491,7 +448,7 @@ abstract class StoragesService { $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); // delete oc_storages entries and oc_filecache - \OC\Files\Cache\Storage::cleanByMountId($id); + Storage::cleanByMountId($id); } /** @@ -510,6 +467,7 @@ abstract class StoragesService { $storage = $storageConfig->getBackend()->wrapStorage($storage); $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); + /** @var \OC\Files\Storage\Storage $storage */ return $storage->getStorageCache()->getNumericId(); } catch (\Exception $e) { return -1; |