2018-03-24 14:39:13 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2022-01-02 02:27:47 -05:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 09:45:36 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-03-24 14:39:13 -04:00
|
|
|
|
2019-05-02 17:17:35 -04:00
|
|
|
namespace Friendica\Console;
|
2018-03-24 14:39:13 -04:00
|
|
|
|
2019-07-28 16:06:33 -04:00
|
|
|
use Friendica\App;
|
2021-10-26 15:44:29 -04:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
/**
|
2020-01-19 01:05:23 -05:00
|
|
|
* Sets maintenance mode for this node
|
2018-03-24 14:39:13 -04:00
|
|
|
*/
|
|
|
|
class Maintenance extends \Asika\SimpleConsole\Console
|
|
|
|
{
|
|
|
|
protected $helpOptions = ['h', 'help', '?'];
|
|
|
|
|
2019-07-28 16:06:33 -04:00
|
|
|
/**
|
|
|
|
* @var App\Mode
|
|
|
|
*/
|
|
|
|
private $appMode;
|
|
|
|
/**
|
2021-10-26 15:44:29 -04:00
|
|
|
* @var IManageConfigValues
|
2019-07-28 16:06:33 -04:00
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2018-03-24 14:39:13 -04: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;
|
|
|
|
}
|
|
|
|
|
2021-10-26 15:44:29 -04:00
|
|
|
public function __construct(App\Mode $appMode, IManageConfigValues $config, $argv = null)
|
2018-03-24 14:39:13 -04:00
|
|
|
{
|
2019-07-28 16:06:33 -04:00
|
|
|
parent::__construct($argv);
|
|
|
|
|
|
|
|
$this->appMode = $appMode;
|
|
|
|
$this->config = $config;
|
|
|
|
}
|
2018-03-26 16:58:34 -04:00
|
|
|
|
2019-07-28 16:06:33 -04:00
|
|
|
protected function doExecute()
|
|
|
|
{
|
2018-03-24 14:39:13 -04: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 16:06:33 -04:00
|
|
|
if ($this->appMode->isInstall()) {
|
2018-06-25 20:56:07 -04:00
|
|
|
throw new \RuntimeException('Database isn\'t ready or populated yet');
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$enabled = intval($this->getArgument(0));
|
|
|
|
|
2019-07-28 16:06:33 -04:00
|
|
|
$this->config->set('system', 'maintenance', $enabled);
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
$reason = $this->getArgument(1);
|
|
|
|
|
|
|
|
if ($enabled && $this->getArgument(1)) {
|
2019-07-28 16:06:33 -04:00
|
|
|
$this->config->set('system', 'maintenance_reason', $this->getArgument(1));
|
2018-03-24 14:39:13 -04:00
|
|
|
} else {
|
2019-07-28 16:06:33 -04:00
|
|
|
$this->config->set('system', 'maintenance_reason', '');
|
2018-03-24 14:39:13 -04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|