DeleteConfig.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\Config\App;
  23. use OCP\IConfig;
  24. use Symfony\Component\Console\Input\InputArgument;
  25. use Symfony\Component\Console\Input\InputInterface;
  26. use Symfony\Component\Console\Input\InputOption;
  27. use Symfony\Component\Console\Output\OutputInterface;
  28. class DeleteConfig extends Base {
  29. public function __construct(
  30. protected IConfig $config,
  31. ) {
  32. parent::__construct();
  33. }
  34. protected function configure() {
  35. parent::configure();
  36. $this
  37. ->setName('config:app:delete')
  38. ->setDescription('Delete an app config value')
  39. ->addArgument(
  40. 'app',
  41. InputArgument::REQUIRED,
  42. 'Name of the app'
  43. )
  44. ->addArgument(
  45. 'name',
  46. InputArgument::REQUIRED,
  47. 'Name of the config to delete'
  48. )
  49. ->addOption(
  50. 'error-if-not-exists',
  51. null,
  52. InputOption::VALUE_NONE,
  53. 'Checks whether the config exists before deleting it'
  54. )
  55. ;
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output): int {
  58. $appName = $input->getArgument('app');
  59. $configName = $input->getArgument('name');
  60. if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) {
  61. $output->writeln('<error>Config ' . $configName . ' of app ' . $appName . ' could not be deleted because it did not exist</error>');
  62. return 1;
  63. }
  64. $this->config->deleteAppValue($appName, $configName);
  65. $output->writeln('<info>Config value ' . $configName . ' of app ' . $appName . ' deleted</info>');
  66. return 0;
  67. }
  68. }