streams/util/config

89 lines
2.1 KiB
Text
Raw Normal View History

#!/usr/bin/env php
<?php
// Red config utility
if(!file_exists('include/cli_startup.php')) {
2019-01-27 20:39:28 +00:00
echo 'Run config from the top level web directory, as util/config <args>' . PHP_EOL;
exit(1);
}
require_once('include/cli_startup.php');
cli_startup();
2016-02-04 04:24:46 +00:00
2016-04-25 09:00:10 +00:00
$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 > 1 && strpos($argv[1],'.')) {
$x = explode('.',$argv[1]);
$argv = [ $argv[0], $x[0], $x[1], (($argc > 2) ? $argv[2] : null) ];
$argc = $argc + 1;
}
2016-04-25 09:00:10 +00:00
if($argc > 3) {
set_config($argv[1],$argv[2],$argv[3]);
2016-02-04 04:24:46 +00:00
echo "config[{$argv[1]}][{$argv[2]}] = " . printable_config(get_config($argv[1],$argv[2])) . "\n";
}
if($argc == 3) {
2016-02-04 04:24:46 +00:00
echo "config[{$argv[1]}][{$argv[2]}] = " . printable_config(get_config($argv[1],$argv[2])) . "\n";
}
if($argc == 2) {
load_config($argv[1]);
2016-03-31 23:06:03 +00:00
foreach(App::$config[$argv[1]] as $k => $x) {
echo "config[{$argv[1]}][{$k}] = " . $x . "\n";
}
}
if($argc == 1) {
2016-09-24 01:52:14 +00:00
$r = q("select * from config where true");
if($r) {
foreach($r as $rr) {
2016-02-04 04:24:46 +00:00
echo "config[{$rr['cat']}][{$rr['k']}] = " . printable_config($rr['v']) . "\n";
}
}
}
2016-02-04 04:24:46 +00:00
function printable_config($x) {
$s = '';
if(is_array($x)) {
2019-01-18 21:04:05 +00:00
return serialise($x);
2016-02-04 04:24:46 +00:00
}
else
return $x;
}