]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/setconfig.php
Make attachment fit better in notice: drop text and link
[quix0rs-gnu-social.git] / scripts / setconfig.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2008, 2009, StatusNet, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 define('INSTALLDIR', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
23
24 $shortoptions = 'da';
25 $longoptions = array('delete', 'all');
26
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.
33
34   [section]   section to use (required)
35   [setting]   setting to use (required)
36   <value>     value to set (optional)
37
38   -d --delete delete the setting (no value)
39   -a --all    list all configuration, not just the database values
40
41 END_OF_SETCONFIG_HELP;
42
43 require_once INSTALLDIR.'/scripts/commandline.inc';
44
45 if (empty($args)) {
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));
52                 }
53             }
54         }
55     } else {
56         $count = 0;
57         $config = new Config();
58         $config->find();
59         while ($config->fetch()) {
60             $count++;
61             printf("%-20s %-20s %s\n", $config->section, $config->setting,
62                    var_export($config->value, true));
63         }
64         if ($count == 0) {
65             print "No configuration set in database for this site.\n";
66         }
67     }
68     exit(0);
69 }
70
71 if (count($args) < 2 || count($args) > 3) {
72     show_help();
73     exit(1);
74 }
75
76 $section = $args[0];
77 $setting = $args[1];
78
79 if (count($args) == 3) {
80     $value = $args[2];
81 } else {
82     $value = null;
83 }
84
85 try {
86
87     if (have_option('d', 'delete')) { // Delete
88         if (count($args) != 2) {
89             show_help();
90             exit(1);
91         }
92
93         if (have_option('v', 'verbose')) {
94             print "Deleting setting $section/$setting...";
95         }
96
97         $setting = Config::pkeyGet(array('section' => $section,
98                                          'setting' => $setting));
99
100         if (empty($setting)) {
101             print "Not found.\n";
102         } else {
103             $result = $setting->delete();
104             if ($result) {
105                 print "DONE.\n";
106             } else {
107                 print "ERROR.\n";
108             }
109         }
110     } else if (count($args) == 2) { // show
111         if (have_option('v', 'verbose')) {
112             print "$section/$setting = ";
113         }
114         $value = common_config($section, $setting);
115         print "$value\n";
116     } else { // set
117         if (have_option('v', 'verbose')) {
118             print "Setting $section/$setting...";
119         }
120         Config::save($section, $setting, $value);
121         print "DONE.\n";
122     }
123
124 } catch (Exception $e) {
125     print $e->getMessage() . "\n";
126     exit(1);
127 }