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;
15 require_once 'include/dba.php';
16 require_once 'include/text.php';
19 * @brief tool to access the system config from the CLI
21 * With this script you can access the system configuration of your node from
22 * the CLI. You can do both, reading current values stored in the database and
23 * set new values to config variables.
26 * If you specify no parameters at the CLI, the script will list all config
29 * If you specify one parameter, the script will list all config variables
30 * defined in this section of the configuration (e.g. "system").
32 * If you specify two parameters, the script will show you the current value
33 * of the named configuration setting. (e.g. "system loglevel")
35 * If you specify three parameters, the named configuration setting will be
36 * set to the value of the last parameter. (e.g. "system loglevel 0" will
39 * @author Tobias Diekershoff
40 * @author Hypolite Petovan <mrpetovan@gmail.com>
42 class Config extends \Asika\SimpleConsole\Console
44 protected $helpOptions = ['h', 'help', '?'];
46 protected function getHelp()
49 console config - Manage site configuration
51 bin/console config [-h|--help|-?] [-v]
52 bin/console config <category> [-h|--help|-?] [-v]
53 bin/console config <category> <key> [-h|--help|-?] [-v]
54 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
58 Lists all config values
60 bin/console config <category>
61 Lists all config values in the provided category
63 bin/console config <category> <key>
64 Shows the value of the provided key in the category
66 bin/console config <category> <key> <value>
67 Sets the value of the provided key in the category
70 Setting config entries which are manually set in config/local.ini.php may result in
71 conflict between database settings and the manual startup settings.
74 -h|--help|-? Show help information
75 -v Show more debug information.
80 protected function doExecute()
84 if ($this->getOption('v')) {
85 $this->out('Executable: ' . $this->executable);
86 $this->out('Class: ' . __CLASS__);
87 $this->out('Arguments: ' . var_export($this->args, true));
88 $this->out('Options: ' . var_export($this->options, true));
91 if (count($this->args) > 3) {
92 throw new CommandArgsException('Too many arguments');
95 if ($a->mode === \Friendica\App::MODE_INSTALL) {
96 $this->out('Database isn\'t ready or populated yet, showing file config only');
99 if (count($this->args) == 3) {
100 $result = Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
102 $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " .
103 Core\Config::get($this->getArgument(0), $this->getArgument(1)));
105 $this->out("Unable to set {$this->getArgument(0)}.{$this->getArgument(1)}");
109 if (count($this->args) == 2) {
110 $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " .
111 Core\Config::get($this->getArgument(0), $this->getArgument(1)));
114 if (count($this->args) == 1) {
115 Core\Config::load($this->getArgument(0));
117 if (!is_null($a->config[$this->getArgument(0)])) {
118 foreach ($a->config[$this->getArgument(0)] as $k => $x) {
119 $this->out("{$this->getArgument(0)}.{$k} = " . $x);
122 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
126 if (count($this->args) == 0) {
129 if (Core\Config::get('system', 'config_adapter') != 'preload' && $a->mode !== \Friendica\App::MODE_INSTALL) {
130 $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
133 foreach ($a->config as $cat => $section) {
134 if (is_array($section)) {
135 foreach ($section as $key => $value) {
136 if (is_array($value)) {
137 foreach ($value as $k => $v) {
138 $this->out("{$cat}.{$key}[{$k}] = " . $v);
141 $this->out("{$cat}.{$key} = " . $value);
145 $this->out("config.{$cat} = " . $section);