Mode.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\Maintenance;
  8. use OCP\IConfig;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Input\InputOption;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class Mode extends Command {
  14. public function __construct(
  15. protected IConfig $config,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure() {
  20. $this
  21. ->setName('maintenance:mode')
  22. ->setDescription('set maintenance mode')
  23. ->addOption(
  24. 'on',
  25. null,
  26. InputOption::VALUE_NONE,
  27. 'enable maintenance mode'
  28. )
  29. ->addOption(
  30. 'off',
  31. null,
  32. InputOption::VALUE_NONE,
  33. 'disable maintenance mode'
  34. );
  35. }
  36. protected function execute(InputInterface $input, OutputInterface $output): int {
  37. $maintenanceMode = $this->config->getSystemValueBool('maintenance');
  38. if ($input->getOption('on')) {
  39. if ($maintenanceMode === false) {
  40. $this->config->setSystemValue('maintenance', true);
  41. $output->writeln('Maintenance mode enabled');
  42. } else {
  43. $output->writeln('Maintenance mode already enabled');
  44. }
  45. } elseif ($input->getOption('off')) {
  46. if ($maintenanceMode === true) {
  47. $this->config->setSystemValue('maintenance', false);
  48. $output->writeln('Maintenance mode disabled');
  49. } else {
  50. $output->writeln('Maintenance mode already disabled');
  51. }
  52. } else {
  53. if ($maintenanceMode) {
  54. $output->writeln('Maintenance mode is currently enabled');
  55. } else {
  56. $output->writeln('Maintenance mode is currently disabled');
  57. }
  58. }
  59. return 0;
  60. }
  61. }