Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

96 lines
2.2KB

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