aboutsummaryrefslogtreecommitdiffstats
path: root/util/config
blob: 5113bd8ecea02d8b4ed43d920b874232d14bdd5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env php
<?php

// Red config utility

require_once('include/cli_startup.php');

cli_startup();


$helpArgs = getopt('h', array('help'));
if (count($helpArgs) === 1) {
	echo <<<'EndOfOutput'
Gets, sets, or lists site-wide configuration settings.

Usage: util/config 
       util/config <family>
       util/config <family> <key>
       util/config <family> <key> <value>

  util/config
	Displays all config entries

  util/config <family>
	Displays all config entries for family (system, database, etc)

  util/config <family> <key>
	Displays single config entry for the specified family and key

  util/config <family> <key> <value>
	Set config entry for specified family and key to value and display result

Notes:
  Setting config entries which are manually set in .htconfig.php may result 
  in conflict between database settings and the manual startup settings. 

  For channel-specific configuration settings, use util/pconfig

  Details for configuration options can be found at:

EndOfOutput;
	echo '    ' . App::get_baseurl() . '/help/hidden_configs' . PHP_EOL . PHP_EOL;
	return;
}



if($argc > 3) {
	set_config($argv[1],$argv[2],$argv[3]);
	echo "config[{$argv[1]}][{$argv[2]}] = " . printable_config(get_config($argv[1],$argv[2])) . "\n";
}

if($argc == 3) {
	echo "config[{$argv[1]}][{$argv[2]}] = " . printable_config(get_config($argv[1],$argv[2])) . "\n";
}

if($argc == 2) {
	load_config($argv[1]);
	foreach(App::$config[$argv[1]] as $k => $x) {
		echo "config[{$argv[1]}][{$k}] = " . $x . "\n";
	}
}

if($argc == 1) {
	$r = q("select * from config where 1");
	if($r) {
		foreach($r as $rr) {
			echo "config[{$rr['cat']}][{$rr['k']}] = " . printable_config($rr['v']) . "\n";
		}
	}
}

function printable_config($x) {
	$s = '';
	if(is_array($x)) {
		foreach($x as $v) {
			$s .= $v . "\n";
		}
		return $s;
	}
	else
		return $x;
}