X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConsole%2FMaintenance.php;h=0cb0da9c60e01596a4f457e72d443d599746d08e;hb=c713c2bf622257dbecf223b5f58bf8a98dde9d65;hp=19067940d178175d6f5c05e35a4ed1b12674487b;hpb=e1423c534244296a22812058a916ce3dbaf802c9;p=friendica.git diff --git a/src/Core/Console/Maintenance.php b/src/Core/Console/Maintenance.php index 19067940d1..0cb0da9c60 100644 --- a/src/Core/Console/Maintenance.php +++ b/src/Core/Console/Maintenance.php @@ -1,105 +1,95 @@ - - */ -class Maintenance extends \Asika\SimpleConsole\Console -{ - protected $helpOptions = ['h', 'help', '?']; - - protected function getHelp() - { - $help = << [] [-h|--help|-?] [-v] - -Description - cen be either 0 or 1 to disabled or enable the maintenance mode on this node. - - 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; - } - - protected function doExecute() - { - 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'); - } - - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); - } - - Core\Config::load(); - - $lang = Core\L10n::getBrowserLanguage(); - Core\L10n::loadTranslationTable($lang); - - $enabled = intval($this->getArgument(0)); - - Core\Config::set('system', 'maintenance', $enabled); - - $reason = $this->getArgument(1); - - if ($enabled && $this->getArgument(1)) { - Core\Config::set('system', 'maintenance_reason', $this->getArgument(1)); - } else { - Core\Config::set('system', 'maintenance_reason', ''); - } - - 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; - } - -} + + */ +class Maintenance extends \Asika\SimpleConsole\Console +{ + protected $helpOptions = ['h', 'help', '?']; + + protected function getHelp() + { + $help = << [] [-h|--help|-?] [-v] + +Description + cen be either 0 or 1 to disabled or enable the maintenance mode on this node. + + 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; + } + + protected function doExecute() + { + $a = \Friendica\BaseObject::getApp(); + + 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'); + } + + if ($a->getMode()->isInstall()) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); + } + + $enabled = intval($this->getArgument(0)); + + Core\Config::set('system', 'maintenance', $enabled); + + $reason = $this->getArgument(1); + + if ($enabled && $this->getArgument(1)) { + Core\Config::set('system', 'maintenance_reason', $this->getArgument(1)); + } else { + Core\Config::set('system', 'maintenance_reason', ''); + } + + 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; + } + +}