3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
25 use Friendica\Core\Config\IConfig;
28 * Sets maintenance mode for this node
30 class Maintenance extends \Asika\SimpleConsole\Console
32 protected $helpOptions = ['h', 'help', '?'];
43 protected function getHelp()
46 console maintenance - Sets maintenance mode for this node
48 bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]
51 <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.
53 <reason> is a quote-enclosed string with the optional reason for the maintenance mode.
56 bin/console maintenance 1
57 Enables the maintenance mode without setting a reason message
59 bin/console maintenance 1 "SSL certification update"
60 Enables the maintenance mode with setting a reason message
62 bin/console maintenance 0
63 Disables the maintenance mode
66 -h|--help|-? Show help information
67 -v Show more debug information.
72 public function __construct(App\Mode $appMode, IConfig $config, $argv = null)
74 parent::__construct($argv);
76 $this->appMode = $appMode;
77 $this->config = $config;
80 protected function doExecute()
82 if ($this->getOption('v')) {
83 $this->out('Class: ' . __CLASS__);
84 $this->out('Arguments: ' . var_export($this->args, true));
85 $this->out('Options: ' . var_export($this->options, true));
88 if (count($this->args) == 0) {
89 $this->out($this->getHelp());
93 if (count($this->args) > 2) {
94 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
97 if ($this->appMode->isInstall()) {
98 throw new \RuntimeException('Database isn\'t ready or populated yet');
101 $enabled = intval($this->getArgument(0));
103 $this->config->set('system', 'maintenance', $enabled);
105 $reason = $this->getArgument(1);
107 if ($enabled && $this->getArgument(1)) {
108 $this->config->set('system', 'maintenance_reason', $this->getArgument(1));
110 $this->config->set('system', 'maintenance_reason', '');
114 $mode_str = "maintenance mode";
116 $mode_str = "normal mode";
119 $this->out('System set in ' . $mode_str);
121 if ($enabled && $reason != '') {
122 $this->out('Maintenance reason: ' . $reason);