3 namespace Friendica\Console;
5 use Asika\SimpleConsole\CommandArgsException;
7 use Friendica\Core\Config\Configuration;
11 * @brief tool to access the system config from the CLI
13 * With this script you can access the system configuration of your node from
14 * the CLI. You can do both, reading current values stored in the database and
15 * set new values to config variables.
18 * If you specify no parameters at the CLI, the script will list all config
21 * If you specify one parameter, the script will list all config variables
22 * defined in this section of the configuration (e.g. "system").
24 * If you specify two parameters, the script will show you the current value
25 * of the named configuration setting. (e.g. "system loglevel")
27 * If you specify three parameters, the named configuration setting will be
28 * set to the value of the last parameter. (e.g. "system loglevel 0" will
31 * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
32 * @author Hypolite Petovan <hypolite@mrpetovan.com>
34 class Config extends \Asika\SimpleConsole\Console
36 protected $helpOptions = ['h', 'help', '?'];
47 protected function getHelp()
50 console config - Manage site configuration
52 bin/console config [-h|--help|-?] [-v]
53 bin/console config <category> [-h|--help|-?] [-v]
54 bin/console config <category> <key> [-h|--help|-?] [-v]
55 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
59 Lists all config values
61 bin/console config <category>
62 Lists all config values in the provided category
64 bin/console config <category> <key>
65 Shows the value of the provided key in the category
67 bin/console config <category> <key> <value>
68 Sets the value of the provided key in the category
71 Setting config entries which are manually set in config/local.config.php may result in
72 conflict between database settings and the manual startup settings.
75 -h|--help|-? Show help information
76 -v Show more debug information.
81 public function __construct(App\Mode $appMode, Configuration $config, array $argv = null)
83 parent::__construct($argv);
85 $this->appMode = $appMode;
86 $this->config = $config;
89 protected function doExecute()
91 if ($this->getOption('v')) {
92 $this->out('Executable: ' . $this->executable);
93 $this->out('Class: ' . __CLASS__);
94 $this->out('Arguments: ' . var_export($this->args, true));
95 $this->out('Options: ' . var_export($this->options, true));
98 if (count($this->args) > 3) {
99 throw new CommandArgsException('Too many arguments');
102 if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
103 $this->out('Database isn\'t ready or populated yet, showing file config only');
106 if (count($this->args) == 3) {
107 $cat = $this->getArgument(0);
108 $key = $this->getArgument(1);
109 $value = $this->getArgument(2);
111 if (is_array($this->config->get($cat, $key))) {
112 throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
115 $result = $this->config->set($cat, $key, $value);
117 $this->out("{$cat}.{$key} <= " .
118 $this->config->get($cat, $key));
120 $this->out("Unable to set {$cat}.{$key}");
124 if (count($this->args) == 2) {
125 $cat = $this->getArgument(0);
126 $key = $this->getArgument(1);
127 $value = $this->config->get($this->getArgument(0), $this->getArgument(1));
129 if (is_array($value)) {
130 foreach ($value as $k => $v) {
131 $this->out("{$cat}.{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
134 $this->out("{$cat}.{$key} => " . $value);
138 if (count($this->args) == 1) {
139 $cat = $this->getArgument(0);
140 $this->config->load($cat);
141 $configCache = $this->config->getCache();
143 if ($configCache->get($cat) !== null) {
144 $this->out("[{$cat}]");
145 $catVal = $configCache->get($cat);
146 foreach ($catVal as $key => $value) {
147 if (is_array($value)) {
148 foreach ($value as $k => $v) {
149 $this->out("{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
152 $this->out("{$key} => " . $value);
156 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
160 if (count($this->args) == 0) {
161 $this->config->load();
163 if ($this->config->get('system', 'config_adapter') == 'jit' && $this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
164 $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
167 $config = $this->config->getCache()->getAll();
168 foreach ($config as $cat => $section) {
169 if (is_array($section)) {
170 foreach ($section as $key => $value) {
171 if (is_array($value)) {
172 foreach ($value as $k => $v) {
173 $this->out("{$cat}.{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
176 $this->out("{$cat}.{$key} => " . $value);
180 $this->out("config.{$cat} => " . $section);