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 Set the value of the provided key in the category
\r
70 -h|--help|-? Show help information
\r
71 -v Show more debug information.
\r
76 protected function doExecute()
\r
78 if ($this->getOption('v')) {
\r
79 $this->out('Executable: ' . $this->executable);
\r
80 $this->out('Class: ' . __CLASS__);
\r
81 $this->out('Arguments: ' . var_export($this->args, true));
\r
82 $this->out('Options: ' . var_export($this->options, true));
\r
85 if (count($this->args) > 3) {
\r
86 throw new CommandArgsException('Too many arguments');
\r
89 require_once '.htconfig.php';
\r
90 $result = dba::connect($db_host, $db_user, $db_pass, $db_data);
\r
91 unset($db_host, $db_user, $db_pass, $db_data);
\r
94 throw new \RuntimeException('Unable to connect to database');
\r
97 if (count($this->args) == 3) {
\r
98 Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2));
\r
99 $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
\r
100 $this->getArgument(1)));
\r
103 if (count($this->args) == 2) {
\r
104 $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0),
\r
105 $this->getArgument(1)));
\r
108 if (count($this->args) == 1) {
\r
109 Core\Config::load($this->getArgument(0));
\r
112 if (!is_null($a->config[$this->getArgument(0)])) {
\r
113 foreach ($a->config[$this->getArgument(0)] as $k => $x) {
\r
114 $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x);
\r
117 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');
\r
121 if (count($this->args) == 0) {
\r
122 $configs = dba::select('config');
\r
123 foreach ($configs as $config) {
\r
124 $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']);
\r