2014-05-27 13:03:53 -04:00
|
|
|
<?php
|
2024-05-24 13:43:47 -04:00
|
|
|
|
2014-05-27 13:03:53 -04:00
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-05-27 13:03:53 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\Maintenance;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IConfig;
|
2014-05-28 16:26:13 -04:00
|
|
|
|
2014-05-27 13:03:53 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
2014-05-28 09:41:34 -04:00
|
|
|
class Mode extends Command {
|
2023-06-13 04:40:10 -04:00
|
|
|
public function __construct(
|
|
|
|
|
protected IConfig $config,
|
|
|
|
|
) {
|
2014-05-28 16:26:13 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 13:03:53 -04:00
|
|
|
protected function configure() {
|
|
|
|
|
$this
|
2014-05-28 09:41:34 -04:00
|
|
|
->setName('maintenance:mode')
|
2024-12-23 18:12:23 -05:00
|
|
|
->setDescription('Show or toggle maintenance mode status')
|
|
|
|
|
->setHelp('Maintenance mode prevents new logins, locks existing sessions, and disables background jobs.')
|
2014-05-27 13:03:53 -04:00
|
|
|
->addOption(
|
|
|
|
|
'on',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'enable maintenance mode'
|
|
|
|
|
)
|
|
|
|
|
->addOption(
|
|
|
|
|
'off',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'disable maintenance mode'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2019-02-06 11:08:41 -05:00
|
|
|
$maintenanceMode = $this->config->getSystemValueBool('maintenance');
|
2014-05-27 13:03:53 -04:00
|
|
|
if ($input->getOption('on')) {
|
2018-07-01 14:56:27 -04:00
|
|
|
if ($maintenanceMode === false) {
|
|
|
|
|
$this->config->setSystemValue('maintenance', true);
|
|
|
|
|
$output->writeln('Maintenance mode enabled');
|
|
|
|
|
} else {
|
|
|
|
|
$output->writeln('Maintenance mode already enabled');
|
|
|
|
|
}
|
2014-05-27 13:03:53 -04:00
|
|
|
} elseif ($input->getOption('off')) {
|
2018-07-01 14:56:27 -04:00
|
|
|
if ($maintenanceMode === true) {
|
|
|
|
|
$this->config->setSystemValue('maintenance', false);
|
|
|
|
|
$output->writeln('Maintenance mode disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$output->writeln('Maintenance mode already disabled');
|
|
|
|
|
}
|
2014-05-27 13:03:53 -04:00
|
|
|
} else {
|
2018-07-01 14:56:27 -04:00
|
|
|
if ($maintenanceMode) {
|
2014-05-27 13:03:53 -04:00
|
|
|
$output->writeln('Maintenance mode is currently enabled');
|
|
|
|
|
} else {
|
|
|
|
|
$output->writeln('Maintenance mode is currently disabled');
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-26 08:54:51 -04:00
|
|
|
return 0;
|
2014-05-27 13:03:53 -04:00
|
|
|
}
|
|
|
|
|
}
|