12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?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 Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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/>
- *
- */
- namespace OCA\User_LDAP\Command;
- use OCA\User_LDAP\Configuration;
- use OCA\User_LDAP\ConnectionFactory;
- use OCA\User_LDAP\Helper;
- use OCA\User_LDAP\LDAP;
- 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 {
- protected function configure(): void {
- $this
- ->setName('ldap:set-config')
- ->setDescription('modifies an LDAP configuration')
- ->addArgument(
- 'configID',
- InputArgument::REQUIRED,
- 'the configuration ID'
- )
- ->addArgument(
- 'configKey',
- InputArgument::REQUIRED,
- 'the configuration key'
- )
- ->addArgument(
- 'configValue',
- InputArgument::REQUIRED,
- 'the new configuration value'
- )
- ;
- }
- protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
- $availableConfigs = $helper->getServerConfigurationPrefixes();
- $configID = $input->getArgument('configID');
- if (!in_array($configID, $availableConfigs)) {
- $output->writeln("Invalid configID");
- return self::FAILURE;
- }
- $this->setValue(
- $configID,
- $input->getArgument('configKey'),
- $input->getArgument('configValue')
- );
- return self::SUCCESS;
- }
- /**
- * save the configuration value as provided
- */
- protected function setValue(string $configID, string $key, string $value): void {
- $configHolder = new Configuration($configID);
- $configHolder->$key = $value;
- $configHolder->saveConfiguration();
- $connectionFactory = new ConnectionFactory(new LDAP());
- $connectionFactory->get($configID)->clearCache();
- }
- }
|