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.

134 lines
4.6 KiB

  1. <?php
  2. namespace Friendica\Core;
  3. /**
  4. * Description of Console
  5. *
  6. * @author Hypolite Petovan <hypolite@mrpetovan.com>
  7. */
  8. class Console extends \Asika\SimpleConsole\Console
  9. {
  10. // Disables the default help handling
  11. protected $helpOptions = [];
  12. protected $customHelpOptions = ['h', 'help', '?'];
  13. protected $subConsoles = [
  14. 'cache' => __NAMESPACE__ . '\Console\Cache',
  15. 'config' => __NAMESPACE__ . '\Console\Config',
  16. 'createdoxygen' => __NAMESPACE__ . '\Console\CreateDoxygen',
  17. 'docbloxerrorchecker' => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
  18. 'dbstructure' => __NAMESPACE__ . '\Console\DatabaseStructure',
  19. 'extract' => __NAMESPACE__ . '\Console\Extract',
  20. 'globalcommunityblock' => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
  21. 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
  22. 'archivecontact' => __NAMESPACE__ . '\Console\ArchiveContact',
  23. 'autoinstall' => __NAMESPACE__ . '\Console\AutomaticInstallation',
  24. 'maintenance' => __NAMESPACE__ . '\Console\Maintenance',
  25. 'newpassword' => __NAMESPACE__ . '\Console\NewPassword',
  26. 'php2po' => __NAMESPACE__ . '\Console\PhpToPo',
  27. 'po2php' => __NAMESPACE__ . '\Console\PoToPhp',
  28. 'typo' => __NAMESPACE__ . '\Console\Typo',
  29. 'postupdate' => __NAMESPACE__ . '\Console\PostUpdate',
  30. 'storage' => __NAMESPACE__ . '\Console\Storage',
  31. ];
  32. protected function getHelp()
  33. {
  34. $help = <<<HELP
  35. Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
  36. Commands:
  37. cache Manage node cache
  38. config Edit site config
  39. createdoxygen Generate Doxygen headers
  40. dbstructure Do database updates
  41. docbloxerrorchecker Check the file tree for DocBlox errors
  42. extract Generate translation string file for the Friendica project (deprecated)
  43. globalcommunityblock Block remote profile from interacting with this node
  44. globalcommunitysilence Silence remote profile from global community page
  45. archivecontact Archive a contact when you know that it isn't existing anymore
  46. help Show help about a command, e.g (bin/console help config)
  47. autoinstall Starts automatic installation of friendica based on values from htconfig.php
  48. maintenance Set maintenance mode for this node
  49. newpassword Set a new password for a given user
  50. php2po Generate a messages.po file from a strings.php file
  51. po2php Generate a strings.php file from a messages.po file
  52. typo Checks for parse errors in Friendica files
  53. postupdate Execute pending post update scripts (can last days)
  54. storage Manage storage backend
  55. Options:
  56. -h|--help|-? Show help information
  57. -v Show more debug information.
  58. HELP;
  59. return $help;
  60. }
  61. protected function doExecute()
  62. {
  63. if ($this->getOption('v')) {
  64. $this->out('Executable: ' . $this->executable);
  65. $this->out('Arguments: ' . var_export($this->args, true));
  66. $this->out('Options: ' . var_export($this->options, true));
  67. }
  68. $subHelp = false;
  69. $command = null;
  70. if ($this->getOption('version')) {
  71. $this->out('Friendica Console version ' . FRIENDICA_VERSION);
  72. return 0;
  73. } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
  74. ) {
  75. } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
  76. $command = $this->getArgument(1);
  77. $subHelp = true;
  78. array_shift($this->args);
  79. array_shift($this->args);
  80. } elseif (count($this->args) >= 1) {
  81. $command = $this->getArgument(0);
  82. array_shift($this->args);
  83. }
  84. if (is_null($command)) {
  85. $this->out($this->getHelp());
  86. return 0;
  87. }
  88. $console = $this->getSubConsole($command);
  89. if ($subHelp) {
  90. $console->setOption($this->customHelpOptions, true);
  91. }
  92. return $console->execute();
  93. }
  94. private function getSubConsole($command)
  95. {
  96. if ($this->getOption('v')) {
  97. $this->out('Command: ' . $command);
  98. }
  99. if (!isset($this->subConsoles[$command])) {
  100. throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
  101. }
  102. $subargs = $this->args;
  103. array_unshift($subargs, $this->executable);
  104. $className = $this->subConsoles[$command];
  105. /** @var Console $subconsole */
  106. $subconsole = new $className($subargs);
  107. foreach ($this->options as $name => $value) {
  108. $subconsole->setOption($name, $value);
  109. }
  110. return $subconsole;
  111. }
  112. }