1
0

CreateEmptyConfig.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\User_LDAP\Command;
  8. use OCA\User_LDAP\Configuration;
  9. use OCA\User_LDAP\Helper;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class CreateEmptyConfig extends Command {
  15. public function __construct(
  16. protected Helper $helper,
  17. ) {
  18. parent::__construct();
  19. }
  20. protected function configure(): void {
  21. $this
  22. ->setName('ldap:create-empty-config')
  23. ->setDescription('creates an empty LDAP configuration')
  24. ->addOption(
  25. 'only-print-prefix',
  26. 'p',
  27. InputOption::VALUE_NONE,
  28. 'outputs only the prefix'
  29. )
  30. ;
  31. }
  32. protected function execute(InputInterface $input, OutputInterface $output): int {
  33. $configPrefix = $this->helper->getNextServerConfigurationPrefix();
  34. $configHolder = new Configuration($configPrefix);
  35. $configHolder->ldapConfigurationActive = false;
  36. $configHolder->saveConfiguration();
  37. $prose = '';
  38. if (!$input->getOption('only-print-prefix')) {
  39. $prose = 'Created new configuration with configID ';
  40. }
  41. $output->writeln($prose . "{$configPrefix}");
  42. return self::SUCCESS;
  43. }
  44. }