3 namespace Friendica\Console;
5 use Asika\SimpleConsole\CommandArgsException;
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', '?'];
38 protected function getHelp()
41 console config - Manage site configuration
43 bin/console config [-h|--help|-?] [-v]
44 bin/console config <category> [-h|--help|-?] [-v]
45 bin/console config <category> <key> [-h|--help|-?] [-v]
46 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
50 Lists all config values
52 bin/console config <category>
53 Lists all config values in the provided category
55 bin/console config <category> <key>
56 Shows the value of the provided key in the category
58 bin/console config <category> <key> <value>
59 Sets the value of the provided key in the category
62 Setting config entries which are manually set in config/local.config.php may result in
63 conflict between database settings and the manual startup settings.
66 -h|--help|-? Show help information
67 -v Show more debug information.
72 protected function doExecute()
74 $a = \Friendica\BaseObject::getApp();
76 if ($this->getOption('v')) {
77 $this->out('Executable: ' . $this->executable);
78 $this->out('Class: ' . __CLASS__);
79 $this->out('Arguments: ' . var_export($this->args, true));
80 $this->out('Options: ' . var_export($this->options, true));
83 if (count($this->args) > 3) {
84 throw new CommandArgsException('Too many arguments');
87 if (!$a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
88 $this->out('Database isn\'t ready or populated yet, showing file config only');
91 if (count($this->args) == 3) {
92 $cat = $this->getArgument(0);
93 $key = $this->getArgument(1);
94 $value = $this->getArgument(2);
96 if (is_array(Core\Config::get($cat, $key))) {
97 throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
100 $result = Core\Config::set($cat, $key, $value);
102 $this->out("{$cat}.{$key} <= " .
103 Core\Config::get($cat, $key));
105 $this->out("Unable to set {$cat}.{$key}");
109 if (count($this->args) == 2) {
110 $cat = $this->getArgument(0);
111 $key = $this->getArgument(1);
112 $value = Core\Config::get($this->getArgument(0), $this->getArgument(1));
114 if (is_array($value)) {
115 foreach ($value as $k => $v) {
116 $this->out("{$cat}.{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
119 $this->out("{$cat}.{$key} => " . $value);
123 if (count($this->args) == 1) {
124 $cat = $this->getArgument(0);
125 Core\Config::load($cat);
127 if ($a->getConfigCache()->get($cat) !== null) {
128 $this->out("[{$cat}]");
129 $catVal = $a->getConfigCache()->get($cat);
130 foreach ($catVal as $key => $value) {
131 if (is_array($value)) {
132 foreach ($value as $k => $v) {
133 $this->out("{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
136 $this->out("{$key} => " . $value);
140 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
144 if (count($this->args) == 0) {
147 if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
148 $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
151 $config = $a->getConfigCache()->getAll();
152 foreach ($config as $cat => $section) {
153 if (is_array($section)) {
154 foreach ($section as $key => $value) {
155 if (is_array($value)) {
156 foreach ($value as $k => $v) {
157 $this->out("{$cat}.{$key}[{$k}] => " . (is_array($v) ? implode(', ', $v) : $v));
160 $this->out("{$cat}.{$key} => " . $value);
164 $this->out("config.{$cat} => " . $section);