You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Mode.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Michael Weimann <mail@michael-weimann.eu>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author scolebrook <scolebrook@mac.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Core\Command\Maintenance;
  27. use OCP\IConfig;
  28. use Symfony\Component\Console\Command\Command;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Input\InputOption;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. class Mode extends Command {
  33. protected IConfig $config;
  34. public function __construct(IConfig $config) {
  35. $this->config = $config;
  36. parent::__construct();
  37. }
  38. protected function configure() {
  39. $this
  40. ->setName('maintenance:mode')
  41. ->setDescription('set maintenance mode')
  42. ->addOption(
  43. 'on',
  44. null,
  45. InputOption::VALUE_NONE,
  46. 'enable maintenance mode'
  47. )
  48. ->addOption(
  49. 'off',
  50. null,
  51. InputOption::VALUE_NONE,
  52. 'disable maintenance mode'
  53. );
  54. }
  55. protected function execute(InputInterface $input, OutputInterface $output): int {
  56. $maintenanceMode = $this->config->getSystemValueBool('maintenance');
  57. if ($input->getOption('on')) {
  58. if ($maintenanceMode === false) {
  59. $this->config->setSystemValue('maintenance', true);
  60. $output->writeln('Maintenance mode enabled');
  61. } else {
  62. $output->writeln('Maintenance mode already enabled');
  63. }
  64. } elseif ($input->getOption('off')) {
  65. if ($maintenanceMode === true) {
  66. $this->config->setSystemValue('maintenance', false);
  67. $output->writeln('Maintenance mode disabled');
  68. } else {
  69. $output->writeln('Maintenance mode already disabled');
  70. }
  71. } else {
  72. if ($maintenanceMode) {
  73. $output->writeln('Maintenance mode is currently enabled');
  74. } else {
  75. $output->writeln('Maintenance mode is currently disabled');
  76. }
  77. }
  78. return 0;
  79. }
  80. }