f9a4f9d2d2d3ffc85b22b7fbbf2b696388e19e07
[friendica.git/.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 tool to silence accounts on the global community page\r
12  *\r
13  * With this tool, you can silence an account on the global community page.\r
14  * Postings from silenced accounts will not be displayed on the community\r
15  * page. This silencing does only affect the display on the community page,\r
16  * accounts following the silenced accounts will still get their postings.\r
17  *\r
18  * Usage: pass the URL of the profile to be silenced account as only parameter\r
19  *        at the command line when running this tool. E.g.\r
20  *\r
21  *        $> util/global_community_silence.php http://example.com/profile/bob\r
22  *\r
23  *        will silence bob@example.com so that his postings won't appear at\r
24  *        the global community page.\r
25  *\r
26  * License: AGPLv3 or later, same as Friendica\r
27  *\r
28  * @author Tobias Diekershoff\r
29  * @author Hypolite Petovan <mrpetovan@gmail.com>\r
30  */\r
31 class Maintenance extends \Asika\SimpleConsole\Console\r
32 {\r
33         protected $helpOptions = ['h', 'help', '?'];\r
34 \r
35         protected function getHelp()\r
36         {\r
37                 $help = <<<HELP\r
38 console maintenance - Sets maintenance mode for this node\r
39 Usage\r
40         bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]\r
41 \r
42 Description\r
43         <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.\r
44 \r
45         <reason> is a quote-enclosed string with the optional reason for the maintenance mode.\r
46 \r
47 Examples\r
48         bin/console maintenance 1\r
49                 Enables the maintenance mode without setting a reason message\r
50 \r
51         bin/console maintenance 1 "SSL certification update"\r
52                 Enables the maintenance mode with setting a reason message\r
53 \r
54         bin/console maintenance 0\r
55                 Disables the maintenance mode\r
56 \r
57 Options\r
58     -h|--help|-? Show help information\r
59     -v           Show more debug information.\r
60 HELP;\r
61                 return $help;\r
62         }\r
63 \r
64         protected function doExecute()\r
65         {\r
66                 if ($this->getOption('v')) {\r
67                         $this->out('Class: ' . __CLASS__);\r
68                         $this->out('Arguments: ' . var_export($this->args, true));\r
69                         $this->out('Options: ' . var_export($this->options, true));\r
70                 }\r
71 \r
72                 if (count($this->args) == 0) {\r
73                         $this->out($this->getHelp());\r
74                         return 0;\r
75                 }\r
76 \r
77                 if (count($this->args) > 2) {\r
78                         throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
79                 }\r
80 \r
81                 require_once '.htconfig.php';\r
82                 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
83                 unset($db_host, $db_user, $db_pass, $db_data);\r
84 \r
85                 if (!$result) {\r
86                         throw new \RuntimeException('Unable to connect to database');\r
87                 }\r
88 \r
89                 Core\Config::load();\r
90 \r
91                 $lang = Core\L10n::getBrowserLanguage();\r
92                 Core\L10n::loadTranslationTable($lang);\r
93 \r
94                 $enabled = intval($this->getArgument(0));\r
95 \r
96                 Core\Config::set('system', 'maintenance', $enabled);\r
97 \r
98                 $reason = $this->getArgument(1);\r
99 \r
100                 if ($enabled && $this->getArgument(1)) {\r
101                         Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));\r
102                 } else {\r
103                         Core\Config::set('system', 'maintenance_reason', '');\r
104                 }\r
105 \r
106                 if ($enabled) {\r
107                         $mode_str = "maintenance mode";\r
108                 } else {\r
109                         $mode_str = "normal mode";\r
110                 }\r
111 \r
112                 $this->out('System set in ' . $mode_str);\r
113 \r
114                 if ($enabled && $reason != '') {\r
115                         $this->out('Maintenance reason: ' . $reason);\r
116                 }\r
117 \r
118                 return 0;\r
119         }\r
120 \r
121 }\r