SetConfig.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 OCA\User_LDAP\ConnectionFactory;
  28. use OCA\User_LDAP\LDAP;
  29. use Symfony\Component\Console\Command\Command;
  30. use Symfony\Component\Console\Input\InputArgument;
  31. use Symfony\Component\Console\Input\InputInterface;
  32. use Symfony\Component\Console\Output\OutputInterface;
  33. use OCA\User_LDAP\Helper;
  34. use OCA\User_LDAP\Configuration;
  35. class SetConfig extends Command {
  36. protected function configure() {
  37. $this
  38. ->setName('ldap:set-config')
  39. ->setDescription('modifies an LDAP configuration')
  40. ->addArgument(
  41. 'configID',
  42. InputArgument::REQUIRED,
  43. 'the configuration ID'
  44. )
  45. ->addArgument(
  46. 'configKey',
  47. InputArgument::REQUIRED,
  48. 'the configuration key'
  49. )
  50. ->addArgument(
  51. 'configValue',
  52. InputArgument::REQUIRED,
  53. 'the new configuration value'
  54. )
  55. ;
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output) {
  58. $helper = new Helper(\OC::$server->getConfig());
  59. $availableConfigs = $helper->getServerConfigurationPrefixes();
  60. $configID = $input->getArgument('configID');
  61. if(!in_array($configID, $availableConfigs)) {
  62. $output->writeln("Invalid configID");
  63. return;
  64. }
  65. $this->setValue(
  66. $configID,
  67. $input->getArgument('configKey'),
  68. $input->getArgument('configValue')
  69. );
  70. }
  71. /**
  72. * save the configuration value as provided
  73. * @param string $configID
  74. * @param string $configKey
  75. * @param string $configValue
  76. */
  77. protected function setValue($configID, $key, $value) {
  78. $configHolder = new Configuration($configID);
  79. $configHolder->$key = $value;
  80. $configHolder->saveConfiguration();
  81. $connectionFactory = new ConnectionFactory(new LDAP());
  82. $connectionFactory->get($configID)->clearCache();
  83. }
  84. }