Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Maintenance.php 2.3KB

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