4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
25 $longoptions = array('delete', 'all');
27 $helptext = <<<END_OF_SETCONFIG_HELP
28 setconfig.php [options] [section] [setting] <value>
29 With three args, set the setting to the value.
30 With two args, just show the setting.
31 With -d, delete the setting.
32 With no args, lists all currently set values.
34 [section] section to use (required)
35 [setting] setting to use (required)
36 <value> value to set (optional)
38 -d --delete delete the setting (no value)
39 -a --all list all configuration, not just the database values
41 END_OF_SETCONFIG_HELP;
43 require_once INSTALLDIR.'/scripts/commandline.inc';
46 if (have_option('a', 'all')) {
47 foreach ($config as $section => $section_value) {
48 foreach ($section_value as $setting => $value) {
49 if (have_option('v', 'verbose') || !is_array($value)) {
50 // Don't print array's without the verbose flag
51 printf("%-20s %-20s %s\n", $section, $setting, var_export($value, true));
57 $config = new Config();
59 while ($config->fetch()) {
61 printf("%-20s %-20s %s\n", $config->section, $config->setting,
62 var_export($config->value, true));
65 print "No configuration set in database for this site.\n";
71 if (count($args) < 2 || count($args) > 3) {
79 if (count($args) == 3) {
87 if (have_option('d', 'delete')) { // Delete
88 if (count($args) != 2) {
93 if (have_option('v', 'verbose')) {
94 print "Deleting setting $section/$setting...";
97 $setting = Config::pkeyGet(array('section' => $section,
98 'setting' => $setting));
100 if (empty($setting)) {
101 print "Not found.\n";
103 $result = $setting->delete();
110 } else if (count($args) == 2) { // show
111 if (have_option('v', 'verbose')) {
112 print "$section/$setting = ";
114 $value = common_config($section, $setting);
117 if (have_option('v', 'verbose')) {
118 print "Setting $section/$setting...";
120 Config::save($section, $setting, $value);
124 } catch (Exception $e) {
125 print $e->getMessage() . "\n";