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