Mode.php 2.1 KB

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