aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Service
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Service')
-rw-r--r--apps/files_external/lib/Service/BackendService.php60
-rw-r--r--apps/files_external/lib/Service/DBConfigService.php81
-rw-r--r--apps/files_external/lib/Service/GlobalStoragesService.php49
-rw-r--r--apps/files_external/lib/Service/ImportLegacyStoragesService.php22
-rw-r--r--apps/files_external/lib/Service/LegacyStoragesService.php43
-rw-r--r--apps/files_external/lib/Service/StoragesService.php79
-rw-r--r--apps/files_external/lib/Service/UserGlobalStoragesService.php34
-rw-r--r--apps/files_external/lib/Service/UserStoragesService.php39
-rw-r--r--apps/files_external/lib/Service/UserTrait.php24
9 files changed, 109 insertions, 322 deletions
diff --git a/apps/files_external/lib/Service/BackendService.php b/apps/files_external/lib/Service/BackendService.php
index 056b288a88b..3a688ee66e6 100644
--- a/apps/files_external/lib/Service/BackendService.php
+++ b/apps/files_external/lib/Service/BackendService.php
@@ -1,40 +1,23 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @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>
- *
- * @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: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;
use OCA\Files_External\Config\IConfigHandler;
+use OCA\Files_External\ConfigLexicon;
use OCA\Files_External\Lib\Auth\AuthMechanism;
-
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
+use OCA\Files_External\Lib\MissingDependency;
use OCP\EventDispatcher\GenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IConfig;
+use OCP\IAppConfig;
+use OCP\Server;
/**
* Service class to manage backend definitions
@@ -52,9 +35,6 @@ class BackendService {
/** Priority constants for PriorityTrait */
public const PRIORITY_DEFAULT = 100;
- /** @var IConfig */
- protected $config;
-
/** @var bool */
private $userMountingAllowed = true;
@@ -78,21 +58,12 @@ class BackendService {
private $configHandlers = [];
- /**
- * @param IConfig $config
- */
public function __construct(
- IConfig $config
+ protected IAppConfig $appConfig,
) {
- $this->config = $config;
-
// Load config values
- if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
- $this->userMountingAllowed = false;
- }
- $this->userMountingBackends = explode(',',
- $this->config->getAppValue('files_external', 'user_mounting_backends', '')
- );
+ $this->userMountingAllowed = $appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING);
+ $this->userMountingBackends = explode(',', $appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS));
// if no backend is in the list an empty string is in the array and user mounting is disabled
if ($this->userMountingBackends === ['']) {
@@ -113,7 +84,7 @@ class BackendService {
private function callForRegistrations() {
static $eventSent = false;
if (!$eventSent) {
- \OC::$server->get(IEventDispatcher::class)->dispatch(
+ Server::get(IEventDispatcher::class)->dispatch(
'OCA\\Files_External::loadAdditionalBackends',
new GenericEvent()
);
@@ -218,7 +189,8 @@ class BackendService {
*/
public function getAvailableBackends() {
return array_filter($this->getBackends(), function ($backend) {
- return !$backend->checkDependencies();
+ $missing = array_filter($backend->checkDependencies(), fn (MissingDependency $dependency) => !$dependency->isOptional());
+ return count($missing) === 0;
});
}
@@ -287,8 +259,8 @@ class BackendService {
* @return bool
*/
protected function isAllowedUserBackend(Backend $backend) {
- if ($this->userMountingAllowed &&
- array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
+ if ($this->userMountingAllowed
+ && array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
) {
return true;
}
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php
index ca1d3a6696c..41ec4512d70 100644
--- a/apps/files_external/lib/Service/DBConfigService.php
+++ b/apps/files_external/lib/Service/DBConfigService.php
@@ -1,29 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @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>
- *
- * @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: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;
@@ -37,31 +17,18 @@ use OCP\Security\ICrypto;
*/
class DBConfigService {
public const MOUNT_TYPE_ADMIN = 1;
+ public const MOUNT_TYPE_PERSONAL = 2;
+ /** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
public const MOUNT_TYPE_PERSONAl = 2;
public const APPLICABLE_TYPE_GLOBAL = 1;
public const APPLICABLE_TYPE_GROUP = 2;
public const APPLICABLE_TYPE_USER = 3;
- /**
- * @var IDBConnection
- */
- private $connection;
-
- /**
- * @var ICrypto
- */
- private $crypto;
-
- /**
- * DBConfigService constructor.
- *
- * @param IDBConnection $connection
- * @param ICrypto $crypto
- */
- public function __construct(IDBConnection $connection, ICrypto $crypto) {
- $this->connection = $connection;
- $this->crypto = $crypto;
+ public function __construct(
+ private IDBConnection $connection,
+ private ICrypto $crypto,
+ ) {
}
public function getMountById(int $mountId): ?array {
@@ -131,7 +98,7 @@ class DBConfigService {
)
)
->groupBy(['a.mount_id']);
- $stmt = $query->execute();
+ $stmt = $query->executeQuery();
$result = $stmt->fetchAll();
$stmt->closeCursor();
@@ -234,7 +201,7 @@ class DBConfigService {
public function getUserMountsFor($type, $value) {
$builder = $this->connection->getQueryBuilder();
$query = $this->getForQuery($builder, $type, $value);
- $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
+ $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));
return $this->getMountsFromQuery($query);
}
@@ -262,7 +229,7 @@ class DBConfigService {
'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
]);
- $query->execute();
+ $query->executeStatement();
return $query->getLastInsertId();
}
@@ -275,22 +242,22 @@ class DBConfigService {
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('external_mounts')
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('external_applicable')
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('external_config')
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
$builder = $this->connection->getQueryBuilder();
$query = $builder->delete('external_options')
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
}
/**
@@ -304,7 +271,7 @@ class DBConfigService {
->set('mount_point', $builder->createNamedParameter($newMountPoint))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
}
/**
@@ -318,7 +285,7 @@ class DBConfigService {
->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
- $query->execute();
+ $query->executeStatement();
}
/**
@@ -344,7 +311,7 @@ class DBConfigService {
->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
- $query->execute();
+ $query->executeStatement();
}
}
@@ -367,7 +334,7 @@ class DBConfigService {
->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
- $query->execute();
+ $query->executeStatement();
}
}
@@ -396,11 +363,11 @@ class DBConfigService {
$query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
}
- $query->execute();
+ $query->executeStatement();
}
private function getMountsFromQuery(IQueryBuilder $query) {
- $result = $query->execute();
+ $result = $query->executeQuery();
$mounts = $result->fetchAll();
$uniqueMounts = [];
foreach ($mounts as $mount) {
@@ -451,7 +418,7 @@ class DBConfigService {
->from($table)
->where($builder->expr()->in('mount_id', $placeHolders));
- $result = $query->execute();
+ $result = $query->executeQuery();
$rows = $result->fetchAll();
$result->closeCursor();
diff --git a/apps/files_external/lib/Service/GlobalStoragesService.php b/apps/files_external/lib/Service/GlobalStoragesService.php
index e3bbed91248..5b1a9f41e48 100644
--- a/apps/files_external/lib/Service/GlobalStoragesService.php
+++ b/apps/files_external/lib/Service/GlobalStoragesService.php
@@ -1,36 +1,15 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @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: 2019-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\Filesystem;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
/**
* Service class to manage global external storage
@@ -52,7 +31,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
$signal,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
['all']
);
return;
@@ -61,13 +40,13 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
$signal,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$applicableUsers
);
$this->triggerApplicableHooks(
$signal,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
$applicableGroups
);
}
@@ -101,7 +80,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_delete_mount,
$oldStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
['all']
);
}
@@ -110,7 +89,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_delete_mount,
$oldStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$userDeletions
);
@@ -118,7 +97,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_delete_mount,
$oldStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
$groupDeletions
);
@@ -126,7 +105,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_create_mount,
$newStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$userAdditions
);
@@ -134,7 +113,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_create_mount,
$newStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
$groupAdditions
);
@@ -146,7 +125,7 @@ class GlobalStoragesService extends StoragesService {
$this->triggerApplicableHooks(
Filesystem::signal_create_mount,
$newStorage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
['all']
);
}
diff --git a/apps/files_external/lib/Service/ImportLegacyStoragesService.php b/apps/files_external/lib/Service/ImportLegacyStoragesService.php
index c17b6fe8fa0..7d9840e9f5e 100644
--- a/apps/files_external/lib/Service/ImportLegacyStoragesService.php
+++ b/apps/files_external/lib/Service/ImportLegacyStoragesService.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @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: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;
diff --git a/apps/files_external/lib/Service/LegacyStoragesService.php b/apps/files_external/lib/Service/LegacyStoragesService.php
index 5b008995b43..9f199a89b3f 100644
--- a/apps/files_external/lib/Service/LegacyStoragesService.php
+++ b/apps/files_external/lib/Service/LegacyStoragesService.php
@@ -1,32 +1,15 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Stefan Weil <sw@weilnetz.de>
- * @author szaimen <szaimen@e.mail.de>
- *
- * @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: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -57,7 +40,7 @@ abstract class LegacyStoragesService {
&$storageConfig,
$mountType,
$applicable,
- $storageOptions
+ $storageOptions,
) {
$backend = $this->backendService->getBackend($storageOptions['backend']);
if (!$backend) {
@@ -82,13 +65,13 @@ abstract class LegacyStoragesService {
$storageOptions['priority'] = $backend->getPriority();
}
$storageConfig->setPriority($storageOptions['priority']);
- if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) {
+ if ($mountType === MountConfig::MOUNT_TYPE_USER) {
$applicableUsers = $storageConfig->getApplicableUsers();
if ($applicable !== 'all') {
$applicableUsers[] = $applicable;
$storageConfig->setApplicableUsers($applicableUsers);
}
- } elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) {
+ } elseif ($mountType === MountConfig::MOUNT_TYPE_GROUP) {
$applicableGroups = $storageConfig->getApplicableGroups();
$applicableGroups[] = $applicable;
$storageConfig->setApplicableGroups($applicableGroups);
@@ -143,13 +126,13 @@ abstract class LegacyStoragesService {
$parts = explode('/', ltrim($rootMountPath, '/'), 3);
if (count($parts) < 3) {
// something went wrong, skip
- \OC::$server->get(LoggerInterface::class)->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
+ Server::get(LoggerInterface::class)->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']);
continue;
}
$relativeMountPath = rtrim($parts[2], '/');
// note: we cannot do this after the loop because the decrypted config
// options might be needed for the config hash
- $storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']);
+ $storageOptions['options'] = MountConfig::decryptPasswords($storageOptions['options']);
if (!isset($storageOptions['backend'])) {
$storageOptions['backend'] = $storageOptions['class']; // legacy compat
}
@@ -167,7 +150,7 @@ abstract class LegacyStoragesService {
// but at this point we don't know the max-id, so use
// first group it by config hash
$storageOptions['mountpoint'] = $rootMountPath;
- $configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions);
+ $configId = MountConfig::makeConfigHash($storageOptions);
if (isset($storagesWithConfigHash[$configId])) {
$currentStorage = $storagesWithConfigHash[$configId];
}
@@ -191,7 +174,7 @@ abstract class LegacyStoragesService {
}
} catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist
- \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
+ Server::get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
'exception' => $e,
]);
diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php
index 78d36c59ba7..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,6 +20,8 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\StorageNotAvailableException;
+use OCP\Server;
+use OCP\Util;
use Psr\Log\LoggerInterface;
/**
@@ -51,37 +29,18 @@ use Psr\Log\LoggerInterface;
*/
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,13 +78,13 @@ abstract class StoragesService {
return $config;
} catch (\UnexpectedValueException $e) {
// don't die if a storage backend doesn't exist
- \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
+ Server::get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
'exception' => $e,
]);
return null;
} catch (\InvalidArgumentException $e) {
- \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [
+ Server::get(LoggerInterface::class)->error('Could not load storage.', [
'app' => 'files_external',
'exception' => $e,
]);
@@ -160,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)) {
@@ -308,7 +267,7 @@ abstract class StoragesService {
$mountOptions = null,
$applicableUsers = null,
$applicableGroups = null,
- $priority = null
+ $priority = null,
) {
$backend = $this->backendService->getBackend($backendIdentifier);
if (!$backend) {
@@ -350,7 +309,7 @@ abstract class StoragesService {
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,
[
@@ -476,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)) {
@@ -489,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);
}
/**
diff --git a/apps/files_external/lib/Service/UserGlobalStoragesService.php b/apps/files_external/lib/Service/UserGlobalStoragesService.php
index 2eda36e9242..aaa59c85d62 100644
--- a/apps/files_external/lib/Service/UserGlobalStoragesService.php
+++ b/apps/files_external/lib/Service/UserGlobalStoragesService.php
@@ -1,25 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;
@@ -37,9 +21,6 @@ use OCP\IUserSession;
class UserGlobalStoragesService extends GlobalStoragesService {
use UserTrait;
- /** @var IGroupManager */
- protected $groupManager;
-
/**
* @param BackendService $backendService
* @param DBConfigService $dbConfig
@@ -52,13 +33,12 @@ class UserGlobalStoragesService extends GlobalStoragesService {
BackendService $backendService,
DBConfigService $dbConfig,
IUserSession $userSession,
- IGroupManager $groupManager,
+ protected IGroupManager $groupManager,
IUserMountCache $userMountCache,
- IEventDispatcher $eventDispatcher
+ IEventDispatcher $eventDispatcher,
) {
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
$this->userSession = $userSession;
- $this->groupManager = $groupManager;
}
/**
@@ -183,7 +163,7 @@ class UserGlobalStoragesService extends GlobalStoragesService {
* @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used
* @return StorageConfig[] array of storage configs
*/
- public function getAllStoragesForUser(IUser $user = null) {
+ public function getAllStoragesForUser(?IUser $user = null) {
if (is_null($user)) {
$user = $this->getUser();
}
diff --git a/apps/files_external/lib/Service/UserStoragesService.php b/apps/files_external/lib/Service/UserStoragesService.php
index 47a6e919853..9d4192734b6 100644
--- a/apps/files_external/lib/Service/UserStoragesService.php
+++ b/apps/files_external/lib/Service/UserStoragesService.php
@@ -1,37 +1,16 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @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: 2018-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\Filesystem;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\NotFoundException;
-
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
use OCP\IUserSession;
@@ -57,7 +36,7 @@ class UserStoragesService extends StoragesService {
DBConfigService $dbConfig,
IUserSession $userSession,
IUserMountCache $userMountCache,
- IEventDispatcher $eventDispatcher
+ IEventDispatcher $eventDispatcher,
) {
$this->userSession = $userSession;
parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher);
@@ -81,7 +60,7 @@ class UserStoragesService extends StoragesService {
$this->triggerApplicableHooks(
$signal,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
[$user]
);
}
@@ -103,7 +82,7 @@ class UserStoragesService extends StoragesService {
}
protected function getType() {
- return DBConfigService::MOUNT_TYPE_PERSONAl;
+ return DBConfigService::MOUNT_TYPE_PERSONAL;
}
/**
@@ -144,7 +123,7 @@ class UserStoragesService extends StoragesService {
}
protected function isApplicable(StorageConfig $config) {
- return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
+ return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAL;
}
public function removeStorage($id) {
diff --git a/apps/files_external/lib/Service/UserTrait.php b/apps/files_external/lib/Service/UserTrait.php
index 260f20cd03b..679066283a5 100644
--- a/apps/files_external/lib/Service/UserTrait.php
+++ b/apps/files_external/lib/Service/UserTrait.php
@@ -1,25 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Service;