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
3.8KB

  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace Friendica\Core\Console;
  8. use Asika\SimpleConsole\CommandArgsException;
  9. use dba;
  10. use Friendica\Core;
  11. require_once 'include/dba.php';
  12. require_once 'include/text.php';
  13. /**
  14. * @brief tool to access the system config from the CLI
  15. *
  16. * With this script you can access the system configuration of your node from
  17. * the CLI. You can do both, reading current values stored in the database and
  18. * set new values to config variables.
  19. *
  20. * Usage:
  21. * If you specify no parameters at the CLI, the script will list all config
  22. * variables defined.
  23. *
  24. * If you specify one parameter, the script will list all config variables
  25. * defined in this section of the configuration (e.g. "system").
  26. *
  27. * If you specify two parameters, the script will show you the current value
  28. * of the named configuration setting. (e.g. "system loglevel")
  29. *
  30. * If you specify three parameters, the named configuration setting will be
  31. * set to the value of the last parameter. (e.g. "system loglevel 0" will
  32. * disable logging)
  33. *
  34. * @author Tobias Diekershoff
  35. * @author Hypolite Petovan <mrpetovan@gmail.com>
  36. */
  37. class Config extends \Asika\SimpleConsole\Console
  38. {
  39. protected $helpOptions = ['h', 'help', '?'];
  40. protected function getHelp()
  41. {
  42. $help = <<<HELP
  43. console config - Manage site configuration
  44. Synopsis
  45. bin/console config [-h|--help|-?] [-v]
  46. bin/console config <category> [-h|--help|-?] [-v]
  47. bin/console config <category> <key> [-h|--help|-?] [-v]
  48. bin/console config <category> <key> <value> [-h|--help|-?] [-v]
  49. Description
  50. bin/console config
  51. Lists all config values
  52. bin/console config <category>
  53. Lists all config values in the provided category
  54. bin/console config <category> <key>
  55. Shows the value of the provided key in the category
  56. bin/console config <category> <key> <value>
  57. Sets the value of the provided key in the category
  58. Notes:
  59. Setting config entries which are manually set in .htconfig.php may result in
  60. conflict between database settings and the manual startup settings.
  61. Options
  62. -h|--help|-? Show help information
  63. -v Show more debug information.
  64. HELP;
  65. return $help;
  66. }
  67. protected function doExecute()
  68. {
  69. $a = get_app();
  70. if ($this->getOption('v')) {
  71. $this->out('Executable: ' . $this->executable);
  72. $this->out('Class: ' . __CLASS__);
  73. $this->out('Arguments: ' . var_export($this->args, true));
  74. $this->out('Options: ' . var_export($this->options, true));
  75. }
  76. if (count($this->args) > 3) {
  77. throw new CommandArgsException('Too many arguments');
  78. }
  79. if ($a->mode === \Friendica\App::MODE_INSTALL) {
  80. $this->out('Database isn\'t ready or populated yet, showing file config only');
  81. }
  82. if (count($this->args) == 3) {
  83. Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
  84. $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
  85. $this->getArgument(1)));
  86. }
  87. if (count($this->args) == 2) {
  88. $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
  89. $this->getArgument(1)));
  90. }
  91. if (count($this->args) == 1) {
  92. Core\Config::load($this->getArgument(0));
  93. $a = get_app();
  94. if (!is_null($a->config[$this->getArgument(0)])) {
  95. foreach ($a->config[$this->getArgument(0)] as $k => $x) {
  96. $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);
  97. }
  98. } else {
  99. $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
  100. }
  101. }
  102. if (count($this->args) == 0) {
  103. $configs = dba::select('config');
  104. foreach ($configs as $config) {
  105. $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);
  106. }
  107. }
  108. return 0;
  109. }
  110. }