3 namespace Friendica\Core\Console;
7 require_once 'boot.php';
8 require_once 'include/dba.php';
11 * @brief Sets maintenance mode for this node
13 * @author Hypolite Petovan <mrpetovan@gmail.com>
15 class Maintenance extends \Asika\SimpleConsole\Console
17 protected $helpOptions = ['h', 'help', '?'];
19 protected function getHelp()
22 console maintenance - Sets maintenance mode for this node
24 bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]
27 <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.
29 <reason> is a quote-enclosed string with the optional reason for the maintenance mode.
32 bin/console maintenance 1
33 Enables the maintenance mode without setting a reason message
35 bin/console maintenance 1 "SSL certification update"
36 Enables the maintenance mode with setting a reason message
38 bin/console maintenance 0
39 Disables the maintenance mode
42 -h|--help|-? Show help information
43 -v Show more debug information.
48 protected function doExecute()
50 if ($this->getOption('v')) {
51 $this->out('Class: ' . __CLASS__);
52 $this->out('Arguments: ' . var_export($this->args, true));
53 $this->out('Options: ' . var_export($this->options, true));
56 if (count($this->args) == 0) {
57 $this->out($this->getHelp());
61 if (count($this->args) > 2) {
62 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
65 require_once '.htconfig.php';
66 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
67 unset($db_host, $db_user, $db_pass, $db_data);
70 throw new \RuntimeException('Unable to connect to database');
75 $lang = Core\L10n::getBrowserLanguage();
76 Core\L10n::loadTranslationTable($lang);
78 $enabled = intval($this->getArgument(0));
80 Core\Config::set('system', 'maintenance', $enabled);
82 $reason = $this->getArgument(1);
84 if ($enabled && $this->getArgument(1)) {
85 Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));
87 Core\Config::set('system', 'maintenance_reason', '');
91 $mode_str = "maintenance mode";
93 $mode_str = "normal mode";
96 $this->out('System set in ' . $mode_str);
98 if ($enabled && $reason != '') {
99 $this->out('Maintenance reason: ' . $reason);