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