SetDefaultModule.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. protected IManager $encryptionManager;
  33. protected IConfig $config;
  34. public function __construct(
  35. IManager $encryptionManager,
  36. IConfig $config
  37. ) {
  38. parent::__construct();
  39. $this->encryptionManager = $encryptionManager;
  40. $this->config = $config;
  41. }
  42. protected function configure() {
  43. parent::configure();
  44. $this
  45. ->setName('encryption:set-default-module')
  46. ->setDescription('Set the encryption default module')
  47. ->addArgument(
  48. 'module',
  49. InputArgument::REQUIRED,
  50. 'ID of the encryption module that should be used'
  51. )
  52. ;
  53. }
  54. protected function execute(InputInterface $input, OutputInterface $output): int {
  55. $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
  56. if ($isMaintenanceModeEnabled) {
  57. $output->writeln("Maintenance mode must be disabled when setting default module,");
  58. $output->writeln("in order to load the relevant encryption modules correctly.");
  59. return 1;
  60. }
  61. $moduleId = $input->getArgument('module');
  62. if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) {
  63. $output->writeln('"' . $moduleId . '"" is already the default module');
  64. } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) {
  65. $output->writeln('<info>Set default module to "' . $moduleId . '"</info>');
  66. } else {
  67. $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>');
  68. return 1;
  69. }
  70. return 0;
  71. }
  72. }