4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
9 namespace Friendica\Core\Console;
11 use Asika\SimpleConsole\CommandArgsException;
16 require_once 'include/dba.php';
17 require_once 'include/text.php';
20 * @brief tool to access the system config from the CLI
22 * With this script you can access the system configuration of your node from
23 * the CLI. You can do both, reading current values stored in the database and
24 * set new values to config variables.
27 * If you specify no parameters at the CLI, the script will list all config
30 * If you specify one parameter, the script will list all config variables
31 * defined in this section of the configuration (e.g. "system").
33 * If you specify two parameters, the script will show you the current value
34 * of the named configuration setting. (e.g. "system loglevel")
36 * If you specify three parameters, the named configuration setting will be
37 * set to the value of the last parameter. (e.g. "system loglevel 0" will
40 * @author Tobias Diekershoff
41 * @author Hypolite Petovan <mrpetovan@gmail.com>
43 class Config extends \Asika\SimpleConsole\Console
45 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.ini.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 protected function doExecute()
85 if ($this->getOption('v')) {
86 $this->out('Executable: ' . $this->executable);
87 $this->out('Class: ' . __CLASS__);
88 $this->out('Arguments: ' . var_export($this->args, true));
89 $this->out('Options: ' . var_export($this->options, true));
92 if (count($this->args) > 3) {
93 throw new CommandArgsException('Too many arguments');
96 if (!($a->mode & App::MODE_DBCONFIGAVAILABLE)) {
97 $this->out('Database isn\'t ready or populated yet, showing file config only');
100 if (count($this->args) == 3) {
101 $cat = $this->getArgument(0);
102 $key = $this->getArgument(1);
103 $value = $this->getArgument(2);
105 if (is_array(Core\Config::get($cat, $key))) {
106 throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
109 $result = Core\Config::set($cat, $key, $value);
111 $this->out("{$cat}.{$key} <= " .
112 Core\Config::get($cat, $key));
114 $this->out("Unable to set {$cat}.{$key}");
118 if (count($this->args) == 2) {
119 $cat = $this->getArgument(0);
120 $key = $this->getArgument(1);
121 $value = Core\Config::get($this->getArgument(0), $this->getArgument(1));
123 if (is_array($value)) {
124 foreach ($value as $k => $v) {
125 $this->out("{$cat}.{$key}[{$k}] => " . $v);
128 $this->out("{$cat}.{$key} => " . $value);
132 if (count($this->args) == 1) {
133 $cat = $this->getArgument(0);
134 Core\Config::load($cat);
136 if (!is_null($a->config[$cat])) {
137 $this->out("[{$cat}]");
138 foreach ($a->config[$cat] as $key => $value) {
139 if (is_array($value)) {
140 foreach ($value as $k => $v) {
141 $this->out("{$key}[{$k}] => " . $v);
144 $this->out("{$key} => " . $value);
148 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
152 if (count($this->args) == 0) {
155 if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->mode & App::MODE_DBCONFIGAVAILABLE) {
156 $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
159 foreach ($a->config as $cat => $section) {
160 if (is_array($section)) {
161 foreach ($section as $key => $value) {
162 if (is_array($value)) {
163 foreach ($value as $k => $v) {
164 $this->out("{$cat}.{$key}[{$k}] => " . $v);
167 $this->out("{$cat}.{$key} => " . $value);
171 $this->out("config.{$cat} => " . $section);