1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Morris Jobke <[email protected]> |
6
|
|
|
* @author scolebrook <[email protected]> |
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
|
|
|
|
24
|
|
|
namespace OC\Core\Command\Maintenance; |
25
|
|
|
|
26
|
|
|
use \OCP\IConfig; |
27
|
|
|
|
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
|
|
|
|
33
|
|
|
class Mode extends Command { |
34
|
|
|
|
35
|
|
|
/** @var IConfig */ |
36
|
|
|
protected $config; |
37
|
|
|
|
38
|
|
|
public function __construct(IConfig $config) { |
39
|
|
|
$this->config = $config; |
40
|
|
|
parent::__construct(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function configure() { |
44
|
|
|
$this |
45
|
|
|
->setName('maintenance:mode') |
46
|
|
|
->setDescription('set maintenance mode') |
47
|
|
|
->addOption( |
48
|
|
|
'on', |
49
|
|
|
null, |
50
|
|
|
InputOption::VALUE_NONE, |
51
|
|
|
'enable maintenance mode' |
52
|
|
|
) |
53
|
|
|
->addOption( |
54
|
|
|
'off', |
55
|
|
|
null, |
56
|
|
|
InputOption::VALUE_NONE, |
57
|
|
|
'disable maintenance mode' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
62
|
|
|
$maintenanceMode = $this->config->getSystemValue('maintenance', false); |
63
|
|
|
if ($input->getOption('on')) { |
64
|
|
|
if ($maintenanceMode === false) { |
65
|
|
|
$this->config->setSystemValue('maintenance', true); |
66
|
|
|
$output->writeln('Maintenance mode enabled'); |
67
|
|
|
} else { |
68
|
|
|
$output->writeln('Maintenance mode already enabled'); |
69
|
|
|
} |
70
|
|
|
} elseif ($input->getOption('off')) { |
71
|
|
|
if ($maintenanceMode === true) { |
72
|
|
|
$this->config->setSystemValue('maintenance', false); |
73
|
|
|
$output->writeln('Maintenance mode disabled'); |
74
|
|
|
} else { |
75
|
|
|
$output->writeln('Maintenance mode already disabled'); |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
if ($maintenanceMode) { |
79
|
|
|
$output->writeln('Maintenance mode is currently enabled'); |
80
|
|
|
} else { |
81
|
|
|
$output->writeln('Maintenance mode is currently disabled'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|