You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setconfig.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\user_ldap\Command;
  24. use Symfony\Component\Console\Command\Command;
  25. use Symfony\Component\Console\Input\InputArgument;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Output\OutputInterface;
  28. use \OCA\user_ldap\lib\Helper;
  29. use \OCA\user_ldap\lib\Configuration;
  30. class SetConfig extends Command {
  31. protected function configure() {
  32. $this
  33. ->setName('ldap:set-config')
  34. ->setDescription('modifies an LDAP configuration')
  35. ->addArgument(
  36. 'configID',
  37. InputArgument::REQUIRED,
  38. 'the configuration ID'
  39. )
  40. ->addArgument(
  41. 'configKey',
  42. InputArgument::REQUIRED,
  43. 'the configuration key'
  44. )
  45. ->addArgument(
  46. 'configValue',
  47. InputArgument::REQUIRED,
  48. 'the new configuration value'
  49. )
  50. ;
  51. }
  52. protected function execute(InputInterface $input, OutputInterface $output) {
  53. $helper = new Helper();
  54. $availableConfigs = $helper->getServerConfigurationPrefixes();
  55. $configID = $input->getArgument('configID');
  56. if(!in_array($configID, $availableConfigs)) {
  57. $output->writeln("Invalid configID");
  58. return;
  59. }
  60. $this->setValue(
  61. $configID,
  62. $input->getArgument('configKey'),
  63. $input->getArgument('configValue')
  64. );
  65. }
  66. /**
  67. * save the configuration value as provided
  68. * @param string $configID
  69. * @param string $configKey
  70. * @param string $configValue
  71. */
  72. protected function setValue($configID, $key, $value) {
  73. $configHolder = new Configuration($configID);
  74. $configHolder->$key = $value;
  75. $configHolder->saveConfiguration();
  76. }
  77. }