SetDefaultModule.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Ruben Homs <ruben@homs.codes>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Core\Command\Encryption;
  25. use OCP\Encryption\IManager;
  26. use OCP\IConfig;
  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. class SetDefaultModule extends Command {
  32. public function __construct(
  33. protected IManager $encryptionManager,
  34. protected IConfig $config,
  35. ) {
  36. parent::__construct();
  37. }
  38. protected function configure() {
  39. parent::configure();
  40. $this
  41. ->setName('encryption:set-default-module')
  42. ->setDescription('Set the encryption default module')
  43. ->addArgument(
  44. 'module',
  45. InputArgument::REQUIRED,
  46. 'ID of the encryption module that should be used'
  47. )
  48. ;
  49. }
  50. protected function execute(InputInterface $input, OutputInterface $output): int {
  51. $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
  52. if ($isMaintenanceModeEnabled) {
  53. $output->writeln("Maintenance mode must be disabled when setting default module,");
  54. $output->writeln("in order to load the relevant encryption modules correctly.");
  55. return 1;
  56. }
  57. $moduleId = $input->getArgument('module');
  58. if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) {
  59. $output->writeln('"' . $moduleId . '"" is already the default module');
  60. } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) {
  61. $output->writeln('<info>Set default module to "' . $moduleId . '"</info>');
  62. } else {
  63. $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>');
  64. return 1;
  65. }
  66. return 0;
  67. }
  68. }