1
0

Mode.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. $maintenanceMode = $this->config->getSystemValueBool('maintenance');
  55. if ($input->getOption('on')) {
  56. if ($maintenanceMode === false) {
  57. $this->config->setSystemValue('maintenance', true);
  58. $output->writeln('Maintenance mode enabled');
  59. } else {
  60. $output->writeln('Maintenance mode already enabled');
  61. }
  62. } elseif ($input->getOption('off')) {
  63. if ($maintenanceMode === true) {
  64. $this->config->setSystemValue('maintenance', false);
  65. $output->writeln('Maintenance mode disabled');
  66. } else {
  67. $output->writeln('Maintenance mode already disabled');
  68. }
  69. } else {
  70. if ($maintenanceMode) {
  71. $output->writeln('Maintenance mode is currently enabled');
  72. } else {
  73. $output->writeln('Maintenance mode is currently disabled');
  74. }
  75. }
  76. }
  77. }