Mode.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /** @var IConfig */
  34. protected $config;
  35. public function __construct(IConfig $config) {
  36. $this->config = $config;
  37. parent::__construct();
  38. }
  39. protected function configure() {
  40. $this
  41. ->setName('maintenance:mode')
  42. ->setDescription('set maintenance mode')
  43. ->addOption(
  44. 'on',
  45. null,
  46. InputOption::VALUE_NONE,
  47. 'enable maintenance mode'
  48. )
  49. ->addOption(
  50. 'off',
  51. null,
  52. InputOption::VALUE_NONE,
  53. 'disable maintenance mode'
  54. );
  55. }
  56. protected function execute(InputInterface $input, OutputInterface $output) {
  57. $maintenanceMode = $this->config->getSystemValueBool('maintenance');
  58. if ($input->getOption('on')) {
  59. if ($maintenanceMode === false) {
  60. $this->config->setSystemValue('maintenance', true);
  61. $output->writeln('Maintenance mode enabled');
  62. } else {
  63. $output->writeln('Maintenance mode already enabled');
  64. }
  65. } elseif ($input->getOption('off')) {
  66. if ($maintenanceMode === true) {
  67. $this->config->setSystemValue('maintenance', false);
  68. $output->writeln('Maintenance mode disabled');
  69. } else {
  70. $output->writeln('Maintenance mode already disabled');
  71. }
  72. } else {
  73. if ($maintenanceMode) {
  74. $output->writeln('Maintenance mode is currently enabled');
  75. } else {
  76. $output->writeln('Maintenance mode is currently disabled');
  77. }
  78. }
  79. }
  80. }