DeleteConfig.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 OC\Core\Command\Config\App;
  8. use OCP\IConfig;
  9. use Symfony\Component\Console\Input\InputArgument;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Input\InputOption;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class DeleteConfig extends Base {
  14. public function __construct(
  15. protected IConfig $config,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure() {
  20. parent::configure();
  21. $this
  22. ->setName('config:app:delete')
  23. ->setDescription('Delete an app config value')
  24. ->addArgument(
  25. 'app',
  26. InputArgument::REQUIRED,
  27. 'Name of the app'
  28. )
  29. ->addArgument(
  30. 'name',
  31. InputArgument::REQUIRED,
  32. 'Name of the config to delete'
  33. )
  34. ->addOption(
  35. 'error-if-not-exists',
  36. null,
  37. InputOption::VALUE_NONE,
  38. 'Checks whether the config exists before deleting it'
  39. )
  40. ;
  41. }
  42. protected function execute(InputInterface $input, OutputInterface $output): int {
  43. $appName = $input->getArgument('app');
  44. $configName = $input->getArgument('name');
  45. if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) {
  46. $output->writeln('<error>Config ' . $configName . ' of app ' . $appName . ' could not be deleted because it did not exist</error>');
  47. return 1;
  48. }
  49. $this->config->deleteAppValue($appName, $configName);
  50. $output->writeln('<info>Config value ' . $configName . ' of app ' . $appName . ' deleted</info>');
  51. return 0;
  52. }
  53. }