SetDefaultModule.php 2.6 KB

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