2018-03-24 18:39:13 +00:00
|
|
|
<?php
|
|
|
|
|
2019-05-02 21:17:35 +00:00
|
|
|
namespace Friendica\Console;
|
2018-03-24 18:39:13 +00:00
|
|
|
|
2019-07-28 20:06:33 +00:00
|
|
|
use Friendica\App;
|
2019-12-19 19:11:07 +00:00
|
|
|
use Friendica\Core\Config\IConfiguration;
|
2018-03-24 18:39:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets maintenance mode for this node
|
|
|
|
*
|
2018-09-15 23:28:38 +00:00
|
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
2018-03-24 18:39:13 +00:00
|
|
|
*/
|
|
|
|
class Maintenance extends \Asika\SimpleConsole\Console
|
|
|
|
{
|
|
|
|
protected $helpOptions = ['h', 'help', '?'];
|
|
|
|
|
2019-07-28 20:06:33 +00:00
|
|
|
/**
|
|
|
|
* @var App\Mode
|
|
|
|
*/
|
|
|
|
private $appMode;
|
|
|
|
/**
|
2019-12-19 19:11:07 +00:00
|
|
|
* @var IConfiguration
|
2019-07-28 20:06:33 +00:00
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2018-03-24 18:39:13 +00:00
|
|
|
protected function getHelp()
|
|
|
|
{
|
|
|
|
$help = <<<HELP
|
|
|
|
console maintenance - Sets maintenance mode for this node
|
|
|
|
Usage
|
|
|
|
bin/console maintenance <enable> [<reason>] [-h|--help|-?] [-v]
|
|
|
|
|
|
|
|
Description
|
|
|
|
<enable> cen be either 0 or 1 to disabled or enable the maintenance mode on this node.
|
|
|
|
|
|
|
|
<reason> is a quote-enclosed string with the optional reason for the maintenance mode.
|
|
|
|
|
|
|
|
Examples
|
|
|
|
bin/console maintenance 1
|
|
|
|
Enables the maintenance mode without setting a reason message
|
|
|
|
|
|
|
|
bin/console maintenance 1 "SSL certification update"
|
|
|
|
Enables the maintenance mode with setting a reason message
|
|
|
|
|
|
|
|
bin/console maintenance 0
|
|
|
|
Disables the maintenance mode
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
HELP;
|
|
|
|
return $help;
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:11:07 +00:00
|
|
|
public function __construct(App\Mode $appMode, IConfiguration $config, $argv = null)
|
2018-03-24 18:39:13 +00:00
|
|
|
{
|
2019-07-28 20:06:33 +00:00
|
|
|
parent::__construct($argv);
|
|
|
|
|
|
|
|
$this->appMode = $appMode;
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
2018-03-26 20:58:34 +00:00
|
|
|
|
2019-07-28 20:06:33 +00:00
|
|
|
protected function doExecute()
|
|
|
|
{
|
2018-03-24 18:39:13 +00:00
|
|
|
if ($this->getOption('v')) {
|
|
|
|
$this->out('Class: ' . __CLASS__);
|
|
|
|
$this->out('Arguments: ' . var_export($this->args, true));
|
|
|
|
$this->out('Options: ' . var_export($this->options, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($this->args) == 0) {
|
|
|
|
$this->out($this->getHelp());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($this->args) > 2) {
|
|
|
|
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
|
|
|
}
|
|
|
|
|
2019-07-28 20:06:33 +00:00
|
|
|
if ($this->appMode->isInstall()) {
|
2018-06-26 00:56:07 +00:00
|
|
|
throw new \RuntimeException('Database isn\'t ready or populated yet');
|
2018-03-24 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$enabled = intval($this->getArgument(0));
|
|
|
|
|
2019-07-28 20:06:33 +00:00
|
|
|
$this->config->set('system', 'maintenance', $enabled);
|
2018-03-24 18:39:13 +00:00
|
|
|
|
|
|
|
$reason = $this->getArgument(1);
|
|
|
|
|
|
|
|
if ($enabled && $this->getArgument(1)) {
|
2019-07-28 20:06:33 +00:00
|
|
|
$this->config->set('system', 'maintenance_reason', $this->getArgument(1));
|
2018-03-24 18:39:13 +00:00
|
|
|
} else {
|
2019-07-28 20:06:33 +00:00
|
|
|
$this->config->set('system', 'maintenance_reason', '');
|
2018-03-24 18:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($enabled) {
|
|
|
|
$mode_str = "maintenance mode";
|
|
|
|
} else {
|
|
|
|
$mode_str = "normal mode";
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out('System set in ' . $mode_str);
|
|
|
|
|
|
|
|
if ($enabled && $reason != '') {
|
|
|
|
$this->out('Maintenance reason: ' . $reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|