3 namespace Friendica\Console;
6 use Friendica\Core\Config\IConfiguration;
9 * @brief Sets maintenance mode for this node
11 * @author Hypolite Petovan <hypolite@mrpetovan.com>
13 class Maintenance extends \Asika\SimpleConsole\Console
15 protected $helpOptions = ['h', 'help', '?'];
26 protected function getHelp()
29 console maintenance - Sets maintenance mode for this node
31 bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]
34 <enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.
36 <reason> is a quote-enclosed string with the optional reason for the maintenance mode.
39 bin/console maintenance 1
40 Enables the maintenance mode without setting a reason message
42 bin/console maintenance 1 "SSL certification update"
43 Enables the maintenance mode with setting a reason message
45 bin/console maintenance 0
46 Disables the maintenance mode
49 -h|--help|-? Show help information
50 -v Show more debug information.
55 public function __construct(App\Mode $appMode, IConfiguration $config, $argv = null)
57 parent::__construct($argv);
59 $this->appMode = $appMode;
60 $this->config = $config;
63 protected function doExecute()
65 if ($this->getOption('v')) {
66 $this->out('Class: ' . __CLASS__);
67 $this->out('Arguments: ' . var_export($this->args, true));
68 $this->out('Options: ' . var_export($this->options, true));
71 if (count($this->args) == 0) {
72 $this->out($this->getHelp());
76 if (count($this->args) > 2) {
77 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
80 if ($this->appMode->isInstall()) {
81 throw new \RuntimeException('Database isn\'t ready or populated yet');
84 $enabled = intval($this->getArgument(0));
86 $this->config->set('system', 'maintenance', $enabled);
88 $reason = $this->getArgument(1);
90 if ($enabled && $this->getArgument(1)) {
91 $this->config->set('system', 'maintenance_reason', $this->getArgument(1));
93 $this->config->set('system', 'maintenance_reason', '');
97 $mode_str = "maintenance mode";
99 $mode_str = "normal mode";
102 $this->out('System set in ' . $mode_str);
104 if ($enabled && $reason != '') {
105 $this->out('Maintenance reason: ' . $reason);