2015-11-24 14:53:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2024-06-06 07:55:47 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-11-24 14:53:02 +00:00
|
|
|
*/
|
|
|
|
namespace OCA\Files_External\Command;
|
|
|
|
|
|
|
|
use OC\Core\Command\Base;
|
2016-05-13 09:56:47 +00:00
|
|
|
use OCA\Files_External\Lib\StorageConfig;
|
|
|
|
use OCA\Files_External\NotFoundException;
|
2016-05-13 09:22:28 +00:00
|
|
|
use OCA\Files_External\Service\GlobalStoragesService;
|
2024-10-02 21:27:44 +00:00
|
|
|
use OCP\AppFramework\Http;
|
2015-11-24 14:53:02 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class Config extends Base {
|
2023-07-04 09:04:36 +00:00
|
|
|
public function __construct(
|
|
|
|
protected GlobalStoragesService $globalService,
|
|
|
|
) {
|
2015-11-24 14:53:02 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2022-10-16 22:54:00 +00:00
|
|
|
protected function configure(): void {
|
2015-11-24 14:53:02 +00:00
|
|
|
$this
|
|
|
|
->setName('files_external:config')
|
|
|
|
->setDescription('Manage backend configuration for a mount')
|
|
|
|
->addArgument(
|
|
|
|
'mount_id',
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'The id of the mount to edit'
|
|
|
|
)->addArgument(
|
|
|
|
'key',
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'key of the config option to set/get'
|
|
|
|
)->addArgument(
|
|
|
|
'value',
|
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
'value to set the config option to, when no value is provided the existing value will be printed'
|
|
|
|
);
|
|
|
|
parent::configure();
|
|
|
|
}
|
|
|
|
|
2020-06-26 13:12:11 +00:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2015-11-24 14:53:02 +00:00
|
|
|
$mountId = $input->getArgument('mount_id');
|
|
|
|
$key = $input->getArgument('key');
|
2015-11-25 15:25:45 +00:00
|
|
|
try {
|
|
|
|
$mount = $this->globalService->getStorage($mountId);
|
|
|
|
} catch (NotFoundException $e) {
|
2015-11-24 14:53:02 +00:00
|
|
|
$output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
|
2024-10-02 21:27:44 +00:00
|
|
|
return Http::STATUS_NOT_FOUND;
|
2015-11-24 14:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$value = $input->getArgument('value');
|
2018-11-27 14:20:23 +00:00
|
|
|
if ($value !== null) {
|
2015-11-24 14:53:02 +00:00
|
|
|
$this->setOption($mount, $key, $value, $output);
|
|
|
|
} else {
|
|
|
|
$this->getOption($mount, $key, $output);
|
|
|
|
}
|
2023-07-04 09:04:36 +00:00
|
|
|
return self::SUCCESS;
|
2015-11-24 14:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
*/
|
2023-07-04 09:04:36 +00:00
|
|
|
protected function getOption(StorageConfig $mount, $key, OutputInterface $output): void {
|
2016-01-12 16:34:22 +00:00
|
|
|
if ($key === 'mountpoint' || $key === 'mount_point') {
|
|
|
|
$value = $mount->getMountPoint();
|
|
|
|
} else {
|
|
|
|
$value = $mount->getBackendOption($key);
|
|
|
|
}
|
2017-04-20 09:31:04 +00:00
|
|
|
if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly
|
2020-04-09 07:22:29 +00:00
|
|
|
$value = json_encode($value);
|
|
|
|
}
|
2024-10-02 22:28:22 +00:00
|
|
|
$output->writeln((string)$value);
|
2015-11-24 14:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
*/
|
2023-07-04 09:04:36 +00:00
|
|
|
protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output): void {
|
2017-04-20 09:31:04 +00:00
|
|
|
$decoded = json_decode($value, true);
|
2020-04-09 07:22:29 +00:00
|
|
|
if (!is_null($decoded) && json_encode($decoded) === $value) {
|
|
|
|
$value = $decoded;
|
|
|
|
}
|
2016-01-12 16:34:22 +00:00
|
|
|
if ($key === 'mountpoint' || $key === 'mount_point') {
|
|
|
|
$mount->setMountPoint($value);
|
|
|
|
} else {
|
|
|
|
$mount->setBackendOption($key, $value);
|
|
|
|
}
|
2015-11-24 14:53:02 +00:00
|
|
|
$this->globalService->updateStorage($mount);
|
|
|
|
}
|
|
|
|
}
|