4 * To change this license header, choose License Headers in Project Properties.
\r
5 * To change this template file, choose Tools | Templates
\r
6 * and open the template in the editor.
\r
9 namespace Friendica\Core\Console;
\r
11 use Asika\SimpleConsole\CommandArgsException;
\r
15 require_once 'include/dba.php';
\r
16 require_once 'include/text.php';
\r
19 * @brief tool to access the system config from the CLI
\r
21 * With this script you can access the system configuration of your node from
\r
22 * the CLI. You can do both, reading current values stored in the database and
\r
23 * set new values to config variables.
\r
26 * If you specify no parameters at the CLI, the script will list all config
\r
27 * variables defined.
\r
29 * If you specify one parameter, the script will list all config variables
\r
30 * defined in this section of the configuration (e.g. "system").
\r
32 * If you specify two parameters, the script will show you the current value
\r
33 * of the named configuration setting. (e.g. "system loglevel")
\r
35 * If you specify three parameters, the named configuration setting will be
\r
36 * set to the value of the last parameter. (e.g. "system loglevel 0" will
\r
39 * @author Tobias Diekershoff
\r
40 * @author Hypolite Petovan <mrpetovan@gmail.com>
\r
42 class Config extends \Asika\SimpleConsole\Console
\r
44 protected $helpOptions = ['h', 'help', '?'];
\r
46 protected function getHelp()
\r
49 console config - Manage site configuration
\r
51 bin/console config [-h|--help|-?] [-v]
\r
52 bin/console config <category> [-h|--help|-?] [-v]
\r
53 bin/console config <category> <key> [-h|--help|-?] [-v]
\r
54 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
\r
58 Lists all config values
\r
60 bin/console config <category>
\r
61 Lists all config values in the provided category
\r
63 bin/console config <category> <key>
\r
64 Shows the value of the provided key in the category
\r
66 bin/console config <category> <key> <value>
\r
67 Sets the value of the provided key in the category
\r
70 Setting config entries which are manually set in .htconfig.php may result in
\r
71 conflict between database settings and the manual startup settings.
\r
74 -h|--help|-? Show help information
\r
75 -v Show more debug information.
\r
80 protected function doExecute()
\r
82 if ($this->getOption('v')) {
\r
83 $this->out('Executable: ' . $this->executable);
\r
84 $this->out('Class: ' . __CLASS__);
\r
85 $this->out('Arguments: ' . var_export($this->args, true));
\r
86 $this->out('Options: ' . var_export($this->options, true));
\r
89 if (count($this->args) > 3) {
\r
90 throw new CommandArgsException('Too many arguments');
\r
93 require_once '.htconfig.php';
\r
94 $result = dba::connect($db_host, $db_user, $db_pass, $db_data);
\r
95 unset($db_host, $db_user, $db_pass, $db_data);
\r
98 throw new \RuntimeException('Unable to connect to database');
\r
101 if (count($this->args) == 3) {
\r
102 Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
\r
103 $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
\r
104 $this->getArgument(1)));
\r
107 if (count($this->args) == 2) {
\r
108 $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
\r
109 $this->getArgument(1)));
\r
112 if (count($this->args) == 1) {
\r
113 Core\Config::load($this->getArgument(0));
\r
116 if (!is_null($a->config[$this->getArgument(0)])) {
\r
117 foreach ($a->config[$this->getArgument(0)] as $k => $x) {
\r
118 $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);
\r
121 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
\r
125 if (count($this->args) == 0) {
\r
126 $configs = dba::select('config');
\r
127 foreach ($configs as $config) {
\r
128 $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);
\r