streams/util/pconfig

111 lines
2.7 KiB
Text
Raw Normal View History

#!/usr/bin/env php
<?php
2022-01-25 01:26:12 +00:00
// personal config utility
2022-02-16 04:08:28 +00:00
use Code\Lib\Libsync;
use Code\Lib\Channel;
2018-06-01 04:05:09 +00:00
if(!file_exists('include/cli_startup.php')) {
2019-01-27 20:39:28 +00:00
echo 'Run pconfig from the top level web directory, as util/pconfig <args>' . PHP_EOL;
exit(1);
}
require_once('include/cli_startup.php');
cli_startup();
2016-04-25 09:30:37 +00:00
$helpArgs = getopt('h', array('help'));
if (count($helpArgs) === 1) {
echo <<<'EndOfOutput'
Gets, sets, or lists personal (per channel) configuration settings.
2016-04-25 09:46:04 +00:00
Usage: util/pconfig
util/pconfig <channel_id>
2016-04-25 09:30:37 +00:00
util/pconfig <channel_id> <family>
util/pconfig <channel_id> <family> <key>
util/pconfig <channel_id> <family> <key> <value>
2016-04-25 09:46:04 +00:00
util/pconfig
List all channel IDs
2016-04-25 09:30:37 +00:00
util/pconfig <channel_id>
Displays all of the the channel's config entries
util/pconfig <channel_id> <family>
Displays all of the channel's config entries for the specified family
(system, database, etc)
util/pconfig <channel_id> <family> <key>
Displays single config entry for the specified family and key
util/pconfig <channel_id> <family> <key> <value>
Set config entry for specified family and key to value and display result
Notes:
For site-wide configuration settings, use util/config
Details for configuration options can be found at:
EndOfOutput;
echo ' ' . App::get_baseurl() . '/help/hidden_configs' . PHP_EOL . PHP_EOL;
return;
}
if($argc > 2 && strpos($argv[2],'.')) {
$x = explode('.',$argv[2]);
$argv = [ $argv[0], $argv[1], $x[0], $x[1], (($argc > 3) ? $argv[3] : null) ];
$argc = $argc + 1;
}
if($argc > 4) {
set_pconfig($argv[1],$argv[2],$argv[3],$argv[4]);
2018-06-05 01:40:11 +00:00
Libsync::build_sync_packet($argv[1]);
2019-01-18 21:04:05 +00:00
echo "pconfig[{$argv[1]}][{$argv[2]}][{$argv[3]}] = " . printable_config(get_pconfig($argv[1],$argv[2],$argv[3])) . "\n";
}
if($argc == 4) {
2019-01-18 21:04:05 +00:00
echo "pconfig[{$argv[1]}][{$argv[2]}][{$argv[3]}] = " . printable_config(get_pconfig($argv[1],$argv[2],$argv[3])) . "\n";
}
if($argc == 3) {
load_pconfig($argv[1],$argv[2]);
if(App::$config[$argv[1]][$argv[2]]) {
foreach(App::$config[$argv[1]][$argv[2]] as $k => $x) {
2019-01-18 21:04:05 +00:00
echo "pconfig[{$argv[1]}][{$argv[2]}][{$k}] = " . printable_config($x) . "\n";
}
}
}
if($argc == 2) {
2021-12-02 23:02:31 +00:00
$r = q('select * from pconfig where uid = ' . intval($argv[1]));
if($r) {
foreach($r as $rr) {
2019-01-18 21:04:05 +00:00
echo "pconfig[{$rr['uid']}][{$rr['cat']}][{$rr['k']}] = " . printable_config($rr['v']) . "\n";
}
}
}
2016-04-25 09:46:04 +00:00
if($argc == 1) {
2021-12-02 23:02:31 +00:00
$r = q('select channel_id, channel_name from channel where channel_removed = 0');
2016-04-25 09:46:04 +00:00
if($r) {
foreach($r as $rr) {
echo sprintf('%4u %s', $rr['channel_id'], $rr['channel_name']) . PHP_EOL;
}
}
}
2019-01-18 21:04:05 +00:00
function printable_config($x) {
$s = '';
if(is_array($x)) {
return serialise($x);
}
else
return $x;
}