diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-10-20 16:53:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 16:53:43 +0200 |
commit | 0f0f132959254432fd40e709dd558a45585e0803 (patch) | |
tree | b79baee2e5c32158a22657640af0d5bf5c77f502 /apps | |
parent | 00c4c3d72332e54b588ccd8009c05cfe724b194a (diff) | |
parent | a5ea677370df4479cc309f4c359599590c24f278 (diff) | |
download | nextcloud-server-0f0f132959254432fd40e709dd558a45585e0803.tar.gz nextcloud-server-0f0f132959254432fd40e709dd558a45585e0803.zip |
Merge pull request #34624 from nextcloud/fix/files_external_psalm
Multiple fix for files external
Diffstat (limited to 'apps')
37 files changed, 329 insertions, 376 deletions
diff --git a/apps/files_external/lib/Command/Applicable.php b/apps/files_external/lib/Command/Applicable.php index 29d5459200e..a3708602dff 100644 --- a/apps/files_external/lib/Command/Applicable.php +++ b/apps/files_external/lib/Command/Applicable.php @@ -36,20 +36,9 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Applicable extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; - - /** - * @var IUserManager - */ - private $userManager; - - /** - * @var IGroupManager - */ - private $groupManager; + protected GlobalStoragesService $globalService; + private IUserManager $userManager; + private IGroupManager $groupManager; public function __construct( GlobalStoragesService $globalService, @@ -62,7 +51,7 @@ class Applicable extends Base { $this->groupManager = $groupManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:applicable') ->setDescription('Manage applicable users and groups for a mount') diff --git a/apps/files_external/lib/Command/Backends.php b/apps/files_external/lib/Command/Backends.php index 60d035f997f..faf6209bd74 100644 --- a/apps/files_external/lib/Command/Backends.php +++ b/apps/files_external/lib/Command/Backends.php @@ -33,8 +33,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Backends extends Base { - /** @var BackendService */ - private $backendService; + private BackendService $backendService; public function __construct(BackendService $backendService ) { @@ -43,7 +42,7 @@ class Backends extends Base { $this->backendService = $backendService; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:backends') ->setDescription('Show available authentication and storage backends') diff --git a/apps/files_external/lib/Command/Config.php b/apps/files_external/lib/Command/Config.php index 5d0675b04bc..1107bfb4d42 100644 --- a/apps/files_external/lib/Command/Config.php +++ b/apps/files_external/lib/Command/Config.php @@ -33,17 +33,14 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Config extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; + protected GlobalStoragesService $globalService; public function __construct(GlobalStoragesService $globalService) { parent::__construct(); $this->globalService = $globalService; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:config') ->setDescription('Manage backend configuration for a mount') diff --git a/apps/files_external/lib/Command/Create.php b/apps/files_external/lib/Command/Create.php index 99991b893cd..17e4731a2d6 100644 --- a/apps/files_external/lib/Command/Create.php +++ b/apps/files_external/lib/Command/Create.php @@ -34,6 +34,7 @@ use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; +use OCA\Files_External\Service\StoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Input\ArrayInput; @@ -43,26 +44,11 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Create extends Base { - /** - * @var GlobalStoragesService - */ - private $globalService; - - /** - * @var UserStoragesService - */ - private $userService; - - /** - * @var IUserManager - */ - private $userManager; - - /** @var BackendService */ - private $backendService; - - /** @var IUserSession */ - private $userSession; + private GlobalStoragesService $globalService; + private UserStoragesService $userService; + private IUserManager $userManager; + private BackendService $backendService; + private IUserSession $userSession; public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, @@ -78,7 +64,7 @@ class Create extends Base { $this->backendService = $backendService; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:create') ->setDescription('Create a new mount configuration') @@ -119,7 +105,7 @@ class Create extends Base { } protected function execute(InputInterface $input, OutputInterface $output): int { - $user = (string) $input->getOption('user'); + $user = (string)$input->getOption('user'); $mountPoint = $input->getArgument('mount_point'); $storageIdentifier = $input->getArgument('storage_backend'); $authIdentifier = $input->getArgument('authentication_backend'); @@ -187,7 +173,7 @@ class Create extends Base { return 0; } - private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) { + private function validateParam(string $key, &$value, Backend $storageBackend, AuthMechanism $authBackend): bool { $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); foreach ($params as $param) { /** @var DefinitionParameter $param */ @@ -201,7 +187,7 @@ class Create extends Base { return false; } - private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { + private function showMount(string $user, StorageConfig $mount, InputInterface $input, OutputInterface $output): void { $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); $listInput = new ArrayInput([], $listCommand->getDefinition()); $listInput->setOption('output', $input->getOption('output')); @@ -209,7 +195,7 @@ class Create extends Base { $listCommand->listMounts($user, [$mount], $listInput, $output); } - protected function getStorageService($userId) { + protected function getStorageService(string $userId): StoragesService { if (!empty($userId)) { $user = $this->userManager->get($userId); if (is_null($user)) { diff --git a/apps/files_external/lib/Command/Delete.php b/apps/files_external/lib/Command/Delete.php index a41161792b5..cf09e3907b7 100644 --- a/apps/files_external/lib/Command/Delete.php +++ b/apps/files_external/lib/Command/Delete.php @@ -37,25 +37,10 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; class Delete extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; - - /** - * @var UserStoragesService - */ - protected $userService; - - /** - * @var IUserSession - */ - protected $userSession; - - /** - * @var IUserManager - */ - protected $userManager; + protected GlobalStoragesService $globalService; + protected UserStoragesService $userService; + protected IUserSession $userSession; + protected IUserManager $userManager; public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { parent::__construct(); @@ -65,7 +50,7 @@ class Delete extends Base { $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:delete') ->setDescription('Delete an external mount') diff --git a/apps/files_external/lib/Command/Export.php b/apps/files_external/lib/Command/Export.php index 622c4b46078..98cfb683060 100644 --- a/apps/files_external/lib/Command/Export.php +++ b/apps/files_external/lib/Command/Export.php @@ -29,7 +29,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Export extends ListCommand { - protected function configure() { + protected function configure(): void { $this ->setName('files_external:export') ->setDescription('Export mount configurations') diff --git a/apps/files_external/lib/Command/Import.php b/apps/files_external/lib/Command/Import.php index 53ae0d7c5bf..eab7dd9a6be 100644 --- a/apps/files_external/lib/Command/Import.php +++ b/apps/files_external/lib/Command/Import.php @@ -40,31 +40,12 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Import extends Base { - /** - * @var GlobalStoragesService - */ - private $globalService; - - /** - * @var UserStoragesService - */ - private $userService; - - /** - * @var IUserSession - */ - private $userSession; - - /** - * @var IUserManager - */ - private $userManager; - - /** @var ImportLegacyStoragesService */ - private $importLegacyStorageService; - - /** @var BackendService */ - private $backendService; + private GlobalStoragesService $globalService; + private UserStoragesService $userService; + private IUserSession $userSession; + private IUserManager $userManager; + private ImportLegacyStoragesService $importLegacyStorageService; + private BackendService $backendService; public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, @@ -82,7 +63,7 @@ class Import extends Base { $this->backendService = $backendService; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:import') ->setDescription('Import mount configurations') @@ -189,7 +170,7 @@ class Import extends Base { return 0; } - private function parseData(array $data) { + private function parseData(array $data): StorageConfig { $mount = new StorageConfig($data['mount_id']); $mount->setMountPoint($data['mount_point']); $mount->setBackend($this->getBackendByClass($data['storage'])); @@ -202,7 +183,7 @@ class Import extends Base { return $mount; } - private function getBackendByClass($className) { + private function getBackendByClass(string $className) { $backends = $this->backendService->getBackends(); foreach ($backends as $backend) { if ($backend->getStorageClass() === $className) { diff --git a/apps/files_external/lib/Command/ListCommand.php b/apps/files_external/lib/Command/ListCommand.php index fadf5d8de27..b2a4baf366b 100644 --- a/apps/files_external/lib/Command/ListCommand.php +++ b/apps/files_external/lib/Command/ListCommand.php @@ -39,25 +39,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListCommand extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; - - /** - * @var UserStoragesService - */ - protected $userService; - - /** - * @var IUserSession - */ - protected $userSession; - - /** - * @var IUserManager - */ - protected $userManager; + protected GlobalStoragesService $globalService; + protected UserStoragesService $userService; + protected IUserSession $userSession; + protected IUserManager $userManager; public const ALL = -1; @@ -69,7 +54,7 @@ class ListCommand extends Base { $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:list') ->setDescription('List configured admin or personal mounts') @@ -102,7 +87,7 @@ class ListCommand extends Base { $mounts = $this->globalService->getStorageForAllUsers(); $userId = self::ALL; } else { - $userId = $input->getArgument('user_id'); + $userId = (string)$input->getArgument('user_id'); $storageService = $this->getStorageService($userId); $mounts = $storageService->getAllStorages(); } @@ -112,12 +97,10 @@ class ListCommand extends Base { } /** - * @param string $userId + * @param ?string|ListCommand::ALL $userId * @param StorageConfig[] $mounts - * @param InputInterface $input - * @param OutputInterface $output */ - public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { + public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void { $outputType = $input->getOption('output'); if (count($mounts) === 0) { if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { diff --git a/apps/files_external/lib/Command/Notify.php b/apps/files_external/lib/Command/Notify.php index 340dd2fdca1..bba698fb25f 100644 --- a/apps/files_external/lib/Command/Notify.php +++ b/apps/files_external/lib/Command/Notify.php @@ -39,27 +39,24 @@ use OCP\Files\Storage\INotifyStorage; use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Notify extends Base { - /** @var GlobalStoragesService */ - private $globalService; - /** @var IDBConnection */ - private $connection; - /** @var ILogger */ - private $logger; + private GlobalStoragesService $globalService; + private IDBConnection $connection; + private LoggerInterface $logger; /** @var IUserManager */ private $userManager; public function __construct( GlobalStoragesService $globalService, IDBConnection $connection, - ILogger $logger, + LoggerInterface $logger, IUserManager $userManager ) { parent::__construct(); @@ -69,7 +66,7 @@ class Notify extends Base { $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:notify') ->setDescription('Listen for active update notifications for a configured external mount') @@ -207,7 +204,7 @@ class Notify extends Base { return 0; } - private function createStorage(StorageConfig $mount) { + private function createStorage(StorageConfig $mount): IStorage { $class = $mount->getBackend()->getStorageClass(); return new $class($mount->getBackendOptions()); } @@ -221,7 +218,7 @@ class Notify extends Base { try { $storages = $this->getStorageIds($mountId, $parent); } catch (DriverException $ex) { - $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); + $this->logger->warning('Error while trying to find correct storage ids.', ['exception' => $ex]); $this->connection = $this->reconnectToDatabase($this->connection, $output); $output->writeln('<info>Needed to reconnect to the database</info>'); $storages = $this->getStorageIds($mountId, $path); @@ -292,37 +289,30 @@ class Notify extends Base { ->fetchAll(); } - /** - * @param array $storageIds - * @param string $parent - * @return int - */ - private function updateParent($storageIds, $parent) { - $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); + private function updateParent(array $storageIds, string $parent): int { + $pathHash = md5(trim((string)\OC_Util::normalizeUnicode($parent), '/')); $qb = $this->connection->getQueryBuilder(); return $qb ->update('filecache') ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) - ->execute(); + ->executeStatement(); } - /** - * @return \OCP\IDBConnection - */ - private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { + private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output): IDBConnection { try { $connection->close(); } catch (\Exception $ex) { - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); + $this->logger->warning('Error while disconnecting from DB', ['exception' => $ex]); $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); } - while (!$connection->isConnected()) { + $connected = false; + while (!$connected) { try { - $connection->connect(); + $connected = $connection->connect(); } catch (\Exception $ex) { - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); + $this->logger->warning('Error while re-connecting to database', ['exception' => $ex]); $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); sleep(60); } diff --git a/apps/files_external/lib/Command/Option.php b/apps/files_external/lib/Command/Option.php index 9f7d4a30bcd..30390ebabee 100644 --- a/apps/files_external/lib/Command/Option.php +++ b/apps/files_external/lib/Command/Option.php @@ -27,7 +27,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; class Option extends Config { - protected function configure() { + protected function configure(): void { $this ->setName('files_external:option') ->setDescription('Manage mount options for a mount') diff --git a/apps/files_external/lib/Command/Verify.php b/apps/files_external/lib/Command/Verify.php index 0febfa15825..f8079ec4d65 100644 --- a/apps/files_external/lib/Command/Verify.php +++ b/apps/files_external/lib/Command/Verify.php @@ -38,17 +38,14 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Verify extends Base { - /** - * @var GlobalStoragesService - */ - protected $globalService; + protected GlobalStoragesService $globalService; public function __construct(GlobalStoragesService $globalService) { parent::__construct(); $this->globalService = $globalService; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:verify') ->setDescription('Verify mount configuration') diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index b82d2a4a4c7..c8eda8658ef 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -294,12 +294,12 @@ abstract class StoragesController extends Controller { } catch (InsufficientDataForMeaningfulAnswerException $e) { $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; $storage->setStatus( - $status, + (int)$status, $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) ); } catch (StorageNotAvailableException $e) { $storage->setStatus( - $e->getCode(), + (int)$e->getCode(), $this->l10n->t('%s', [$e->getMessage()]) ); } catch (\Exception $e) { diff --git a/apps/files_external/lib/Lib/Auth/AuthMechanism.php b/apps/files_external/lib/Lib/Auth/AuthMechanism.php index 929068ea7ef..e43f6d06b47 100644 --- a/apps/files_external/lib/Lib/Auth/AuthMechanism.php +++ b/apps/files_external/lib/Lib/Auth/AuthMechanism.php @@ -29,6 +29,8 @@ use OCA\Files_External\Lib\IdentifierTrait; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageModifierTrait; use OCA\Files_External\Lib\VisibilityTrait; +use OCA\Files_External\Lib\IIdentifier; +use OCA\Files_External\Lib\IFrontendDefinition; /** * Authentication mechanism @@ -50,7 +52,7 @@ use OCA\Files_External\Lib\VisibilityTrait; * - StorageModifierTrait * Object can affect storage mounting */ -class AuthMechanism implements \JsonSerializable { +class AuthMechanism implements \JsonSerializable, IIdentifier, IFrontendDefinition { /** Standard authentication schemes */ public const SCHEME_NULL = 'null'; public const SCHEME_BUILTIN = 'builtin'; diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php index 053d9b87952..d0058e98b52 100644 --- a/apps/files_external/lib/Lib/Backend/Backend.php +++ b/apps/files_external/lib/Lib/Backend/Backend.php @@ -30,6 +30,9 @@ use OCA\Files_External\Lib\PriorityTrait; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageModifierTrait; use OCA\Files_External\Lib\VisibilityTrait; +use OCA\Files_External\Lib\IIdentifier; +use OCA\Files_External\Lib\IFrontendDefinition; +use OCP\Files\Storage\IStorage; /** * Storage backend @@ -55,7 +58,7 @@ use OCA\Files_External\Lib\VisibilityTrait; * - StorageModifierTrait * Object can affect storage mounting */ -class Backend implements \JsonSerializable { +class Backend implements \JsonSerializable, IIdentifier, IFrontendDefinition { use VisibilityTrait; use FrontendDefinitionTrait; use PriorityTrait; @@ -73,7 +76,7 @@ class Backend implements \JsonSerializable { private $legacyAuthMechanism; /** - * @return string + * @return class-string<IStorage> */ public function getStorageClass() { return $this->storageClass; @@ -118,21 +121,17 @@ class Backend implements \JsonSerializable { return $this->legacyAuthMechanism; } - /** - * @param AuthMechanism $authMechanism - * @return self - */ - public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { + public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self { $this->legacyAuthMechanism = $authMechanism; return $this; } /** * @param callable $callback dynamic auth mechanism selection - * @return self */ - public function setLegacyAuthMechanismCallback(callable $callback) { + public function setLegacyAuthMechanismCallback(callable $callback): self { $this->legacyAuthMechanism = $callback; + return $this; } /** diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php index b10d3a0b276..fd72b2fa7aa 100644 --- a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php +++ b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php @@ -29,62 +29,45 @@ namespace OCA\Files_External\Lib; trait FrontendDefinitionTrait { /** @var string human-readable mechanism name */ - private $text; + private string $text = ""; - /** @var DefinitionParameter[] parameters for mechanism */ - private $parameters = []; + /** @var array<string, DefinitionParameter> parameters for mechanism */ + private array $parameters = []; /** @var string[] custom JS */ - private $customJs = []; + private array $customJs = []; - /** - * @return string - */ - public function getText() { + public function getText(): string { return $this->text; } - /** - * @param string $text - * @return $this - */ - public function setText($text) { + public function setText(string $text): self { $this->text = $text; return $this; } - /** - * @param FrontendDefinitionTrait $a - * @param FrontendDefinitionTrait $b - * @return int - */ - public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) { + public static function lexicalCompare(IFrontendDefinition $a, IFrontendDefinition $b): int { return strcmp($a->getText(), $b->getText()); } /** - * @return DefinitionParameter[] + * @return array<string, DefinitionParameter> */ - public function getParameters() { + public function getParameters(): array { return $this->parameters; } /** - * @param DefinitionParameter[] $parameters - * @return self + * @param list<DefinitionParameter> $parameters */ - public function addParameters(array $parameters) { + public function addParameters(array $parameters): self { foreach ($parameters as $parameter) { $this->addParameter($parameter); } return $this; } - /** - * @param DefinitionParameter $parameter - * @return self - */ - public function addParameter(DefinitionParameter $parameter) { + public function addParameter(DefinitionParameter $parameter): self { $this->parameters[$parameter->getName()] = $parameter; return $this; } @@ -92,7 +75,7 @@ trait FrontendDefinitionTrait { /** * @return string[] */ - public function getCustomJs() { + public function getCustomJs(): array { return $this->customJs; } @@ -100,17 +83,15 @@ trait FrontendDefinitionTrait { * @param string $custom * @return self */ - public function addCustomJs($custom) { + public function addCustomJs(string $custom): self { $this->customJs[] = $custom; return $this; } /** * Serialize into JSON for client-side JS - * - * @return array */ - public function jsonSerializeDefinition() { + public function jsonSerializeDefinition(): array { $configuration = []; foreach ($this->getParameters() as $parameter) { $configuration[$parameter->getName()] = $parameter; @@ -126,11 +107,8 @@ trait FrontendDefinitionTrait { /** * Check if parameters are satisfied in a StorageConfig - * - * @param StorageConfig $storage - * @return bool */ - public function validateStorageDefinition(StorageConfig $storage) { + public function validateStorageDefinition(StorageConfig $storage): bool { foreach ($this->getParameters() as $name => $parameter) { $value = $storage->getBackendOption($name); if (!is_null($value) || !$parameter->isOptional()) { diff --git a/apps/files_external/lib/Lib/IFrontendDefinition.php b/apps/files_external/lib/Lib/IFrontendDefinition.php new file mode 100644 index 00000000000..3c625c21c15 --- /dev/null +++ b/apps/files_external/lib/Lib/IFrontendDefinition.php @@ -0,0 +1,56 @@ +<?php +/** + * @copyright 2022 Carl Schwan <carl@carlschwan.eu> + * + * @license AGPL-3.0-or-later + * + * 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/> + * + */ +namespace OCA\Files_External\Lib; + +interface IFrontendDefinition { + + public function getText(): string; + + public function setText(string $text): self; + + /** + * @return array<string, DefinitionParameter> + */ + public function getParameters(): array; + + /** + * @param list<DefinitionParameter> $parameters + */ + public function addParameters(array $parameters): self; + + public function addParameter(DefinitionParameter $parameter): self; + + /** + * @return string[] + */ + public function getCustomJs(): array; + + public function addCustomJs(string $custom): self; + + /** + * Serialize into JSON for client-side JS + */ + public function jsonSerializeDefinition(): array; + + /** + * Check if parameters are satisfied in a StorageConfig + */ + public function validateStorageDefinition(StorageConfig $storage): bool; +} diff --git a/apps/files_external/lib/Lib/IIdentifier.php b/apps/files_external/lib/Lib/IIdentifier.php new file mode 100644 index 00000000000..b410f5333d5 --- /dev/null +++ b/apps/files_external/lib/Lib/IIdentifier.php @@ -0,0 +1,27 @@ +<?php +/** + * @copyright 2022 Carl Schwan <carl@carlschwan.eu> + * + * @license AGPL-3.0-or-later + * + * 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/> + * + */ +namespace OCA\Files_External\Lib; + +interface IIdentifier { + + public function getIdentifier(): string; + + public function setIdentifier(string $identifier): self; +} diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/apps/files_external/lib/Lib/IdentifierTrait.php index 37813795490..52eff147a02 100644 --- a/apps/files_external/lib/Lib/IdentifierTrait.php +++ b/apps/files_external/lib/Lib/IdentifierTrait.php @@ -28,27 +28,17 @@ namespace OCA\Files_External\Lib; */ trait IdentifierTrait { - /** @var string */ - protected $identifier; + protected string $identifier = ''; /** @var string[] */ - protected $identifierAliases = []; + protected array $identifierAliases = []; + protected ?IIdentifier $deprecateTo = null; - /** @var IdentifierTrait */ - protected $deprecateTo = null; - - /** - * @return string - */ - public function getIdentifier() { + public function getIdentifier(): string { return $this->identifier; } - /** - * @param string $identifier - * @return $this - */ - public function setIdentifier($identifier) { + public function setIdentifier(string $identifier): self { $this->identifier = $identifier; $this->identifierAliases[] = $identifier; return $this; @@ -57,39 +47,25 @@ trait IdentifierTrait { /** * @return string[] */ - public function getIdentifierAliases() { + public function getIdentifierAliases(): array { return $this->identifierAliases; } - /** - * @param string $alias - * @return $this - */ - public function addIdentifierAlias($alias) { + public function addIdentifierAlias(string $alias): self { $this->identifierAliases[] = $alias; return $this; } - /** - * @return object|null - */ - public function getDeprecateTo() { + public function getDeprecateTo(): ?IIdentifier { return $this->deprecateTo; } - /** - * @param object $destinationObject - * @return self - */ - public function deprecateTo($destinationObject) { + public function deprecateTo(IIdentifier $destinationObject): self { $this->deprecateTo = $destinationObject; return $this; } - /** - * @return array - */ - public function jsonSerializeIdentifier() { + public function jsonSerializeIdentifier(): array { $data = [ 'identifier' => $this->identifier, 'identifierAliases' => $this->identifierAliases, diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php index 732413c78cd..42a72e960ea 100644 --- a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php +++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php @@ -21,13 +21,15 @@ */ namespace OCA\Files_External\Lib; +use OCP\Files\Storage\IStorage; + /** * Polyfill for checking dependencies using legacy Storage::checkDependencies() */ trait LegacyDependencyCheckPolyfill { /** - * @return string + * @return class-string<IStorage> */ abstract public function getStorageClass(); @@ -54,7 +56,7 @@ trait LegacyDependencyCheckPolyfill { $module = $key; $message = $value; } - $value = new MissingDependency($module, $this); + $value = new MissingDependency($module); $value->setMessage($message); } $ret[] = $value; diff --git a/apps/files_external/lib/Lib/MissingDependency.php b/apps/files_external/lib/Lib/MissingDependency.php index b740f4596b2..a8e9f9ecc45 100644 --- a/apps/files_external/lib/Lib/MissingDependency.php +++ b/apps/files_external/lib/Lib/MissingDependency.php @@ -39,17 +39,11 @@ class MissingDependency { $this->dependency = $dependency; } - /** - * @return string - */ - public function getDependency() { + public function getDependency(): string { return $this->dependency; } - /** - * @return string|null - */ - public function getMessage() { + public function getMessage(): ?string { return $this->message; } diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/apps/files_external/lib/Lib/PriorityTrait.php index 355f75a833a..299d25c9b40 100644 --- a/apps/files_external/lib/Lib/PriorityTrait.php +++ b/apps/files_external/lib/Lib/PriorityTrait.php @@ -47,13 +47,4 @@ trait PriorityTrait { $this->priority = $priority; return $this; } - - /** - * @param PriorityTrait $a - * @param PriorityTrait $b - * @return int - */ - public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) { - return ($a->getPriority() - $b->getPriority()); - } } diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index d5b8eff6fe5..9e91b89d29e 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -55,11 +55,14 @@ use OCP\ICacheFactory; use OCP\IMemcache; use OCP\Server; use OCP\ICache; +use Psr\Log\LoggerInterface; class AmazonS3 extends \OC\Files\Storage\Common { use S3ConnectionTrait; use S3ObjectTrait; + private LoggerInterface $logger; + public function needsPartFile() { return false; } @@ -88,6 +91,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { /** @var ICacheFactory $cacheFactory */ $cacheFactory = Server::get(ICacheFactory::class); $this->memCache = $cacheFactory->createLocal('s3-external'); + $this->logger = Server::get(LoggerInterface::class); } /** @@ -255,7 +259,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { ]); $this->testTimeout(); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } @@ -286,18 +293,11 @@ class AmazonS3 extends \OC\Files\Storage\Common { protected function clearBucket() { $this->clearCache(); - try { - $this->getConnection()->clearBucket([ - "Bucket" => $this->bucket - ]); - return true; - // clearBucket() is not working with Ceph, so if it fails we try the slower approach - } catch (\Exception $e) { - return $this->batchDelete(); - } + return $this->batchDelete(); } private function batchDelete($path = null) { + // TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html $params = [ 'Bucket' => $this->bucket ]; @@ -327,7 +327,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->deleteObject($path); } } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } return true; @@ -415,7 +418,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { try { return $this->doesDirectoryExist($path); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } } @@ -438,7 +444,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { return 'dir'; } } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } @@ -464,7 +473,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->deleteObject($path); $this->invalidateCache($path); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } @@ -486,7 +498,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { try { return $this->readObject($path); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } case 'w': @@ -548,7 +563,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->testTimeout(); } } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } @@ -556,65 +574,71 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function copy($path1, $path2, $isFile = null) { - $path1 = $this->normalizePath($path1); - $path2 = $this->normalizePath($path2); + public function copy($source, $target, $isFile = null) { + $source = $this->normalizePath($source); + $target = $this->normalizePath($target); - if ($isFile === true || $this->is_file($path1)) { + if ($isFile === true || $this->is_file($source)) { try { $this->getConnection()->copyObject([ 'Bucket' => $this->bucket, - 'Key' => $this->cleanKey($path2), - 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $path1) + 'Key' => $this->cleanKey($target), + 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $source) ]); $this->testTimeout(); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } } else { - $this->remove($path2); + $this->remove($target); try { - $this->mkdir($path2); + $this->mkdir($target); $this->testTimeout(); } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } - foreach ($this->getDirectoryContent($path1) as $item) { - $source = $path1 . '/' . $item['name']; - $target = $path2 . '/' . $item['name']; + foreach ($this->getDirectoryContent($source) as $item) { + $source = $source . '/' . $item['name']; + $target = $target . '/' . $item['name']; $this->copy($source, $target, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER); } } - $this->invalidateCache($path2); + $this->invalidateCache($target); return true; } - public function rename($path1, $path2) { - $path1 = $this->normalizePath($path1); - $path2 = $this->normalizePath($path2); + public function rename($source, $target) { + $source = $this->normalizePath($source); + $target = $this->normalizePath($target); - if ($this->is_file($path1)) { - if ($this->copy($path1, $path2) === false) { + if ($this->is_file($source)) { + if ($this->copy($source, $target) === false) { return false; } - if ($this->unlink($path1) === false) { - $this->unlink($path2); + if ($this->unlink($source) === false) { + $this->unlink($target); return false; } } else { - if ($this->copy($path1, $path2) === false) { + if ($this->copy($source, $target) === false) { return false; } - if ($this->rmdir($path1) === false) { - $this->rmdir($path2); + if ($this->rmdir($source) === false) { + $this->rmdir($target); return false; } } @@ -642,7 +666,10 @@ class AmazonS3 extends \OC\Files\Storage\Common { unlink($tmpFile); return true; } catch (S3Exception $e) { - \OC::$server->getLogger()->logException($e, ['app' => 'files_external']); + $this->logger->error($e->getMessage(), [ + 'app' => 'files_external', + 'exception' => $e, + ]); return false; } } diff --git a/apps/files_external/lib/Lib/Storage/FTP.php b/apps/files_external/lib/Lib/Storage/FTP.php index d424ffe3cdd..0350035a11a 100644 --- a/apps/files_external/lib/Lib/Storage/FTP.php +++ b/apps/files_external/lib/Lib/Storage/FTP.php @@ -333,9 +333,9 @@ class FTP extends Common { } } - public function rename($path1, $path2) { - $this->unlink($path2); - return $this->getConnection()->rename($this->buildPath($path1), $this->buildPath($path2)); + public function rename($source, $target) { + $this->unlink($target); + return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target)); } public function getDirectoryContent($directory): \Traversable { diff --git a/apps/files_external/lib/Lib/Storage/FtpConnection.php b/apps/files_external/lib/Lib/Storage/FtpConnection.php index bc4be18e42e..c6f9a5c91b0 100644 --- a/apps/files_external/lib/Lib/Storage/FtpConnection.php +++ b/apps/files_external/lib/Lib/Storage/FtpConnection.php @@ -85,8 +85,8 @@ class FtpConnection { return @ftp_rmdir($this->connection, $path); } - public function rename(string $path1, string $path2) { - return @ftp_rename($this->connection, $path1, $path2); + public function rename(string $source, string $target) { + return @ftp_rename($this->connection, $source, $target); } public function mdtm(string $path) { diff --git a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php index 06ede120f5a..680a51cfa10 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php @@ -36,7 +36,7 @@ class SFTPReadStream implements File { /** @var \phpseclib\Net\SFTP */ private $sftp; - /** @var resource */ + /** @var string */ private $handle; /** @var int */ @@ -61,7 +61,6 @@ class SFTPReadStream implements File { * Load the source from the stream context and return the context options * * @param string $name - * @return array * @throws \BadMethodCallException */ protected function loadContext($name) { @@ -202,5 +201,6 @@ class SFTPReadStream implements File { if (!$this->sftp->_close_handle($this->handle)) { return false; } + return true; } } diff --git a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php index b1518809f09..6682a49d8f6 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php @@ -36,7 +36,7 @@ class SFTPWriteStream implements File { /** @var \phpseclib\Net\SFTP */ private $sftp; - /** @var resource */ + /** @var string */ private $handle; /** @var int */ @@ -61,7 +61,6 @@ class SFTPWriteStream implements File { * Load the source from the stream context and return the context options * * @param string $name - * @return array * @throws \BadMethodCallException */ protected function loadContext($name) { @@ -180,5 +179,6 @@ class SFTPWriteStream implements File { if (!$this->sftp->_close_handle($this->handle)) { return false; } + return true; } } diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 6c59263ddd5..1d4cf5a7a2e 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -282,7 +282,7 @@ class SMB extends Common implements INotifyStorage { } } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while getting folder content']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -310,7 +310,7 @@ class SMB extends Common implements INotifyStorage { * @param string $target the new name of the path * @return bool true if the rename is successful, false otherwise */ - public function rename($source, $target, $retry = true) { + public function rename($source, $target, $retry = true): bool { if ($this->isRootDir($source) || $this->isRootDir($target)) { return false; } @@ -322,7 +322,7 @@ class SMB extends Common implements INotifyStorage { } catch (AlreadyExistsException $e) { if ($retry) { $this->remove($target); - $result = $this->share->rename($absoluteSource, $absoluteTarget, false); + $result = $this->share->rename($absoluteSource, $absoluteTarget); } else { $this->logger->logException($e, ['level' => ILogger::WARN]); return false; @@ -330,7 +330,7 @@ class SMB extends Common implements INotifyStorage { } catch (InvalidArgumentException $e) { if ($retry) { $this->remove($target); - $result = $this->share->rename($absoluteSource, $absoluteTarget, false); + $result = $this->share->rename($absoluteSource, $absoluteTarget); } else { $this->logger->logException($e, ['level' => ILogger::WARN]); return false; @@ -428,7 +428,7 @@ class SMB extends Common implements INotifyStorage { return false; } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while deleting file']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -515,7 +515,7 @@ class SMB extends Common implements INotifyStorage { throw new EntityTooLargeException("not enough available space to create file", 0, $e); } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while opening file']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -542,7 +542,7 @@ class SMB extends Common implements INotifyStorage { return false; } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while removing folder']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -558,7 +558,7 @@ class SMB extends Common implements INotifyStorage { throw new EntityTooLargeException("not enough available space to create file", 0, $e); } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while creating file']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } @@ -655,7 +655,7 @@ class SMB extends Common implements INotifyStorage { return true; } catch (ConnectException $e) { $this->logger->logException($e, ['message' => 'Error while creating folder']); - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } catch (Exception $e) { return false; } @@ -670,7 +670,7 @@ class SMB extends Common implements INotifyStorage { } catch (ForbiddenException $e) { return false; } catch (ConnectException $e) { - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); + throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e); } } diff --git a/apps/files_external/lib/Lib/Storage/StreamWrapper.php b/apps/files_external/lib/Lib/Storage/StreamWrapper.php index dc203399646..79387e14cf6 100644 --- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php +++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php @@ -117,8 +117,8 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { return copy($path, $this->constructUrl($target)); } - public function rename($path1, $path2) { - return rename($this->constructUrl($path1), $this->constructUrl($path2)); + public function rename($source, $target) { + return rename($this->constructUrl($source), $this->constructUrl($target)); } public function stat($path) { diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index cc0ee6c7c21..85b3727f4db 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -482,25 +482,25 @@ class Swift extends \OC\Files\Storage\Common { } } - public function copy($path1, $path2) { - $path1 = $this->normalizePath($path1); - $path2 = $this->normalizePath($path2); + public function copy($source, $target) { + $source = $this->normalizePath($source); + $target = $this->normalizePath($target); - $fileType = $this->filetype($path1); + $fileType = $this->filetype($source); if ($fileType) { // make way - $this->unlink($path2); + $this->unlink($target); } if ($fileType === 'file') { try { - $source = $this->fetchObject($path1); - $source->copy([ - 'destination' => $this->bucket . '/' . $path2 + $sourceObject = $this->fetchObject($source); + $sourceObject->copy([ + 'destination' => $this->bucket . '/' . $target ]); // invalidate target object to force repopulation on fetch - $this->objectCache->remove($path2); - $this->objectCache->remove($path2 . '/'); + $this->objectCache->remove($target); + $this->objectCache->remove($target . '/'); } catch (BadResponseError $e) { \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, @@ -510,13 +510,13 @@ class Swift extends \OC\Files\Storage\Common { } } elseif ($fileType === 'dir') { try { - $source = $this->fetchObject($path1 . '/'); - $source->copy([ - 'destination' => $this->bucket . '/' . $path2 . '/' + $sourceObject = $this->fetchObject($source . '/'); + $sourceObject->copy([ + 'destination' => $this->bucket . '/' . $target . '/' ]); // invalidate target object to force repopulation on fetch - $this->objectCache->remove($path2); - $this->objectCache->remove($path2 . '/'); + $this->objectCache->remove($target); + $this->objectCache->remove($target . '/'); } catch (BadResponseError $e) { \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, @@ -525,14 +525,14 @@ class Swift extends \OC\Files\Storage\Common { return false; } - $dh = $this->opendir($path1); + $dh = $this->opendir($source); while ($file = readdir($dh)) { if (\OC\Files\Filesystem::isIgnoredDir($file)) { continue; } - $source = $path1 . '/' . $file; - $target = $path2 . '/' . $file; + $source = $source . '/' . $file; + $target = $target . '/' . $file; $this->copy($source, $target); } } else { @@ -543,22 +543,22 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function rename($path1, $path2) { - $path1 = $this->normalizePath($path1); - $path2 = $this->normalizePath($path2); + public function rename($source, $target) { + $source = $this->normalizePath($source); + $target = $this->normalizePath($target); - $fileType = $this->filetype($path1); + $fileType = $this->filetype($source); if ($fileType === 'dir' || $fileType === 'file') { // copy - if ($this->copy($path1, $path2) === false) { + if ($this->copy($source, $target) === false) { return false; } // cleanup - if ($this->unlink($path1) === false) { + if ($this->unlink($source) === false) { throw new \Exception('failed to remove original'); - $this->unlink($path2); + $this->unlink($target); return false; } diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index 20e5aea62d2..757f9d35bdb 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -126,17 +126,17 @@ class StorageConfig implements \JsonSerializable { /** * Creates a storage config * - * @param int|null $id config id or null for a new config + * @param int|string $id config id or null for a new config */ public function __construct($id = null) { - $this->id = $id; + $this->id = $id ?? -1; $this->mountOptions['enable_sharing'] = false; } /** * Returns the configuration id * - * @return int + * @retun int */ public function getId() { return $this->id; @@ -147,7 +147,7 @@ class StorageConfig implements \JsonSerializable { * * @param int $id configuration id */ - public function setId($id) { + public function setId(int $id): void { $this->id = $id; } diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index a95ea01add9..23d72bdcf18 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -150,17 +150,17 @@ class MountConfig { * TODO: move into AppFramework along with templates * * @param Backend[] $backends - * @return string */ - public static function dependencyMessage($backends) { + public static function dependencyMessage(array $backends): string { $l = \OC::$server->getL10N('files_external'); $message = ''; $dependencyGroups = []; foreach ($backends as $backend) { foreach ($backend->checkDependencies() as $dependency) { - if ($message = $dependency->getMessage()) { - $message .= '<p>' . $message . '</p>'; + $dependencyMessage = $dependency->getMessage(); + if ($dependencyMessage !== null) { + $message .= '<p>' . $dependencyMessage . '</p>'; } else { $dependencyGroups[$dependency->getDependency()][] = $backend; } @@ -168,7 +168,7 @@ class MountConfig { } foreach ($dependencyGroups as $module => $dependants) { - $backends = implode(', ', array_map(function ($backend) { + $backends = implode(', ', array_map(function (Backend $backend): string { return '"' . $backend->getText() . '"'; }, $dependants)); $message .= '<p>' . MountConfig::getSingleDependencyMessage($l, $module, $backends) . '</p>'; @@ -179,13 +179,8 @@ class MountConfig { /** * Returns a dependency missing message - * - * @param \OCP\IL10N $l - * @param string $module - * @param string $backend - * @return string */ - private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) { + private static function getSingleDependencyMessage(\OCP\IL10N $l, string $module, string $backend): string { switch (strtolower($module)) { case 'curl': return $l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$backend]); diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php index f6446eea363..bc089d18fbd 100644 --- a/apps/files_external/lib/Service/DBConfigService.php +++ b/apps/files_external/lib/Service/DBConfigService.php @@ -64,11 +64,7 @@ class DBConfigService { $this->crypto = $crypto; } - /** - * @param int $mountId - * @return array - */ - public function getMountById($mountId) { + public function getMountById(int $mountId): ?array { $builder = $this->connection->getQueryBuilder(); $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) ->from('external_mounts', 'm') diff --git a/apps/files_external/lib/Service/GlobalStoragesService.php b/apps/files_external/lib/Service/GlobalStoragesService.php index 509d4fde8d9..e3bbed91248 100644 --- a/apps/files_external/lib/Service/GlobalStoragesService.php +++ b/apps/files_external/lib/Service/GlobalStoragesService.php @@ -155,7 +155,7 @@ class GlobalStoragesService extends StoragesService { /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return int BackendService::VISIBILITY_* constants */ public function getVisibilityType() { return BackendService::VISIBILITY_ADMIN; diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index eaa2ebf7e95..bd1793c93bc 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -231,7 +231,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(); @@ -510,6 +510,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; diff --git a/apps/files_external/lib/Service/UserStoragesService.php b/apps/files_external/lib/Service/UserStoragesService.php index b09b37b40cc..9a1e4e648b3 100644 --- a/apps/files_external/lib/Service/UserStoragesService.php +++ b/apps/files_external/lib/Service/UserStoragesService.php @@ -134,7 +134,7 @@ class UserStoragesService extends StoragesService { /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return int BackendService::VISIBILITY_* constants */ public function getVisibilityType() { return BackendService::VISIBILITY_PERSONAL; diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index d8dd91822c5..af7438e28d7 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -1,9 +1,11 @@ <?php - use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\Backend\Backend; use \OCA\Files_External\Lib\Auth\AuthMechanism; use \OCA\Files_External\Lib\DefinitionParameter; use \OCA\Files_External\Service\BackendService; +/** @var array $_ */ + $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; $l->t("Enable encryption"); diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index f4ad29cb74c..b5c0da9c442 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -334,15 +334,15 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto /** * see https://www.php.net/manual/en/function.rename.php * - * @param string $path1 - * @param string $path2 + * @param string $source + * @param string $target * @return bool */ - public function rename($path1, $path2): bool { + public function rename($source, $target): bool { $this->init(); - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; - $targetExists = $this->file_exists($path2); - $sameFolder = dirname($path1) === dirname($path2); + $isPartFile = pathinfo($source, PATHINFO_EXTENSION) === 'part'; + $targetExists = $this->file_exists($target); + $sameFolder = dirname($source) === dirname($target); if ($targetExists || ($sameFolder && !$isPartFile)) { if (!$this->isUpdatable('')) { @@ -354,7 +354,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto } } - return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); + return $this->nonMaskedStorage->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target)); } /** |