]> git.mxchange.org Git - friendica.git/blob - src/Core/Console/Config.php
Remove util/config*
[friendica.git] / src / Core / Console / Config.php
1 <?php\r
2 \r
3 /*\r
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
7  */\r
8 \r
9 namespace Friendica\Core\Console;\r
10 \r
11 use Asika\SimpleConsole\CommandArgsException;\r
12 use dba;\r
13 use Friendica\Core;\r
14 \r
15 require_once 'include/dba.php';\r
16 require_once 'include/text.php';\r
17 \r
18 /**\r
19  * @brief tool to access the system config from the CLI\r
20  *\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
24  *\r
25  * Usage:\r
26  *   If you specify no parameters at the CLI, the script will list all config\r
27  *   variables defined.\r
28  *\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
31  *\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
34  *\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
37  *   disable logging)\r
38  *\r
39  * @author Tobias Diekershoff\r
40  * @author Hypolite Petovan <mrpetovan@gmail.com>\r
41  */\r
42 class Config extends \Asika\SimpleConsole\Console\r
43 {\r
44         protected $helpOptions = ['h', 'help', '?'];\r
45 \r
46         protected function getHelp()\r
47         {\r
48                 $help = <<<HELP\r
49 console config - Manage site configuration\r
50 Synopsis\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
55 \r
56 Description\r
57         bin/console config\r
58                 Lists all config values\r
59 \r
60         bin/console config <category>\r
61                 Lists all config values in the provided category\r
62 \r
63         bin/console config <category> <key>\r
64                 Shows the value of the provided key in the category\r
65 \r
66         bin/console config <category> <key> <value>\r
67                 Sets the value of the provided key in the category\r
68 \r
69 Notes:\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
72 \r
73 Options\r
74     -h|--help|-? Show help information\r
75     -v           Show more debug information.\r
76 HELP;\r
77                 return $help;\r
78         }\r
79 \r
80         protected function doExecute()\r
81         {\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
87                 }\r
88 \r
89                 if (count($this->args) > 3) {\r
90                         throw new CommandArgsException('Too many arguments');\r
91                 }\r
92 \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
96 \r
97                 if (!$result) {\r
98                         throw new \RuntimeException('Unable to connect to database');\r
99                 }\r
100 \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
105                 }\r
106 \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
110                 }\r
111 \r
112                 if (count($this->args) == 1) {\r
113                         Core\Config::load($this->getArgument(0));\r
114 \r
115                         $a = get_app();\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
119                                 }\r
120                         } else {\r
121                                 $this->out('Config section ' . $this->getArgument(0) . ' returned nothing');\r
122                         }\r
123                 }\r
124 \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
129                         }\r
130                 }\r
131 \r
132                 return 0;\r
133         }\r
134 \r
135 }\r