2014-06-03 06:35:18 -04:00
|
|
|
<?php
|
2024-05-29 05:32:54 -04:00
|
|
|
|
2014-06-03 06:35:18 -04:00
|
|
|
/**
|
2024-05-29 05:32:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-06-03 06:35:18 -04:00
|
|
|
*/
|
2016-05-12 03:59:29 -04:00
|
|
|
namespace OCA\User_LDAP\Command;
|
2014-06-03 06:35:18 -04:00
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\User_LDAP\Configuration;
|
2018-12-16 18:31:27 -05:00
|
|
|
use OCA\User_LDAP\ConnectionFactory;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\User_LDAP\Helper;
|
2018-12-16 18:31:27 -05:00
|
|
|
use OCA\User_LDAP\LDAP;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Server;
|
2014-06-03 06:35:18 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class SetConfig extends Command {
|
2024-01-24 02:38:56 -05:00
|
|
|
protected function configure(): void {
|
2014-06-03 06:35:18 -04:00
|
|
|
$this
|
|
|
|
|
->setName('ldap:set-config')
|
2014-06-03 06:36:42 -04:00
|
|
|
->setDescription('modifies an LDAP configuration')
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
2023-11-23 04:22:34 -05:00
|
|
|
'configID',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the configuration ID'
|
|
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
2023-11-23 04:22:34 -05:00
|
|
|
'configKey',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the configuration key'
|
|
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
->addArgument(
|
2023-11-23 04:22:34 -05:00
|
|
|
'configValue',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'the new configuration value'
|
|
|
|
|
)
|
2014-06-03 06:35:18 -04:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 09:12:11 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2025-05-22 09:40:16 -04:00
|
|
|
$helper = Server::get(Helper::class);
|
2014-08-21 11:59:13 -04:00
|
|
|
$availableConfigs = $helper->getServerConfigurationPrefixes();
|
2014-06-03 06:35:18 -04:00
|
|
|
$configID = $input->getArgument('configID');
|
2020-04-10 08:19:56 -04:00
|
|
|
if (!in_array($configID, $availableConfigs)) {
|
2024-08-23 09:10:27 -04:00
|
|
|
$output->writeln('Invalid configID');
|
2024-01-24 02:38:56 -05:00
|
|
|
return self::FAILURE;
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setValue(
|
|
|
|
|
$configID,
|
|
|
|
|
$input->getArgument('configKey'),
|
|
|
|
|
$input->getArgument('configValue')
|
|
|
|
|
);
|
2024-01-24 02:38:56 -05:00
|
|
|
return self::SUCCESS;
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* save the configuration value as provided
|
|
|
|
|
*/
|
2024-01-24 02:38:56 -05:00
|
|
|
protected function setValue(string $configID, string $key, string $value): void {
|
2014-06-03 06:35:18 -04:00
|
|
|
$configHolder = new Configuration($configID);
|
|
|
|
|
$configHolder->$key = $value;
|
|
|
|
|
$configHolder->saveConfiguration();
|
2018-12-16 18:31:27 -05:00
|
|
|
|
|
|
|
|
$connectionFactory = new ConnectionFactory(new LDAP());
|
|
|
|
|
$connectionFactory->get($configID)->clearCache();
|
2014-06-03 06:35:18 -04:00
|
|
|
}
|
|
|
|
|
}
|