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