SetConfig.php 2.5 KB

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