mirror of
https://github.com/nextcloud/server.git
synced 2026-04-29 10:03:32 -04:00
Add more typing to FilesExternal commands
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
parent
cf1381a6f9
commit
2d75321c23
11 changed files with 52 additions and 139 deletions
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -43,26 +43,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 +63,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')
|
||||
|
|
@ -187,7 +172,7 @@ class Create extends Base {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
|
||||
private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend): bool {
|
||||
$params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
|
||||
foreach ($params as $param) {
|
||||
/** @var DefinitionParameter $param */
|
||||
|
|
@ -201,7 +186,7 @@ class Create extends Base {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
|
||||
private function showMount($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 +194,7 @@ class Create extends Base {
|
|||
$listCommand->listMounts($user, [$mount], $listInput, $output);
|
||||
}
|
||||
|
||||
protected function getStorageService($userId) {
|
||||
protected function getStorageService(string $userId) {
|
||||
if (!empty($userId)) {
|
||||
$user = $this->userManager->get($userId);
|
||||
if (is_null($user)) {
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -114,10 +99,8 @@ class ListCommand extends Base {
|
|||
/**
|
||||
* @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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -307,7 +304,7 @@ class Notify extends Base {
|
|||
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>");
|
||||
}
|
||||
$connected = false;
|
||||
|
|
@ -315,7 +312,7 @@ class Notify extends Base {
|
|||
try {
|
||||
$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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue