]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/Maintenance.php
Merge pull request #4630 from MrPetovan/task/4629-move-executable-to-bin
[friendica.git] / src / Core / Console / Maintenance.php
1 <?php\r
2 \r
3 namespace Friendica\Core\Console;\r
4 \r
5 use Friendica\Core;\r
6 \r
7 require_once 'boot.php';\r
8 require_once 'include/dba.php';\r
9 \r
10 /**\r
11  * @brief Sets maintenance mode for this node\r
12  *\r
13  * @author Hypolite Petovan <mrpetovan@gmail.com>\r
14  */\r
15 class Maintenance extends \Asika\SimpleConsole\Console\r
16 {\r
17         protected $helpOptions = ['h', 'help', '?'];\r
18 \r
19         protected function getHelp()\r
20         {\r
21                 $help = <<<HELP\r
22 console maintenance - Sets maintenance mode for this node\r
23 Usage\r
24         bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]\r
25 \r
26 Description\r
27         <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.\r
28 \r
29         <reason> is a quote-enclosed string with the optional reason for the maintenance mode.\r
30 \r
31 Examples\r
32         bin/console maintenance 1\r
33                 Enables the maintenance mode without setting a reason message\r
34 \r
35         bin/console maintenance 1 "SSL certification update"\r
36                 Enables the maintenance mode with setting a reason message\r
37 \r
38         bin/console maintenance 0\r
39                 Disables the maintenance mode\r
40 \r
41 Options\r
42     -h|--help|-? Show help information\r
43     -v           Show more debug information.\r
44 HELP;\r
45                 return $help;\r
46         }\r
47 \r
48         protected function doExecute()\r
49         {\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
54                 }\r
55 \r
56                 if (count($this->args) == 0) {\r
57                         $this->out($this->getHelp());\r
58                         return 0;\r
59                 }\r
60 \r
61                 if (count($this->args) > 2) {\r
62                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
63                 }\r
64 \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
68 \r
69                 if (!$result) {\r
70                         throw new \RuntimeException('Unable to connect to database');\r
71                 }\r
72 \r
73                 Core\Config::load();\r
74 \r
75                 $lang = Core\L10n::getBrowserLanguage();\r
76                 Core\L10n::loadTranslationTable($lang);\r
77 \r
78                 $enabled = intval($this->getArgument(0));\r
79 \r
80                 Core\Config::set('system', 'maintenance', $enabled);\r
81 \r
82                 $reason = $this->getArgument(1);\r
83 \r
84                 if ($enabled && $this->getArgument(1)) {\r
85                         Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));\r
86                 } else {\r
87                         Core\Config::set('system', 'maintenance_reason', '');\r
88                 }\r
89 \r
90                 if ($enabled) {\r
91                         $mode_str = "maintenance mode";\r
92                 } else {\r
93                         $mode_str = "normal mode";\r
94                 }\r
95 \r
96                 $this->out('System set in ' . $mode_str);\r
97 \r
98                 if ($enabled && $reason != '') {\r
99                         $this->out('Maintenance reason: ' . $reason);\r
100                 }\r
101 \r
102                 return 0;\r
103         }\r
104 \r
105 }\r