You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.8 KiB
165 lines
4.8 KiB
#!/usr/bin/php
|
|
<?php
|
|
|
|
### DO NOT EDIT THIS FILE
|
|
|
|
function usage() {
|
|
echo "\n";
|
|
echo "Get and Set configuration parameters\n";
|
|
echo "\n";
|
|
echo "Usage:\n";
|
|
echo "\n";
|
|
echo "config get [configPath]\n";
|
|
echo "config set [configPath] [value]\n";
|
|
echo "config remove [configPath]\n";
|
|
echo "\n";
|
|
echo "configPath: The config path is in the format 'project_manager.workspaces_dir'\n";
|
|
echo "\n";
|
|
echo "--help Prints this message\n";
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['argc'] < 3 || $_SERVER['argv'] == '--help') {
|
|
usage();
|
|
}
|
|
|
|
global $project_manager_dir, $shortname, $configuration;
|
|
$configuration = [];
|
|
$project_manager_dir = dirname(dirname(__DIR__));
|
|
$command = $_SERVER['argv'][1];
|
|
$configPath = $_SERVER['argv'][2];
|
|
$value = $_SERVER['argv'][3] ?? null;
|
|
$shortname = substr($configPath, 0, strpos($configPath, '.'));
|
|
$configPath = substr($configPath, strpos($configPath, '.')+1);
|
|
|
|
if (function_exists($command)) {
|
|
loadProjectManagerConfig($project_manager_dir);
|
|
if ($shortname !== 'project_manager') {
|
|
loadProjectConfig();
|
|
}
|
|
$command();
|
|
}
|
|
|
|
function mergeConfig($file)
|
|
{
|
|
global $configuration;
|
|
$configuration = array_replace_recursive(
|
|
$configuration,
|
|
json_decode(file_get_contents($file), true)
|
|
);
|
|
}
|
|
|
|
function loadProjectManagerConfig()
|
|
{
|
|
global $configuration, $project_manager_dir;
|
|
$config_file = $project_manager_dir . '/etc/config.json';
|
|
mergeConfig($config_file);
|
|
}
|
|
|
|
function loadProjectConfig()
|
|
{
|
|
global $configuration, $project_manager_dir;
|
|
$customer = getCustomerFromShortname();
|
|
$project = getProjectFromShortname();
|
|
|
|
$config_file = "$project_manager_dir/data/$customer/$project/etc/config.json";
|
|
mergeConfig($config_file);
|
|
|
|
$plugin_dir = dirname($config_file) . '/plugins';
|
|
$dh = opendir($plugin_dir);
|
|
if ($dh) {
|
|
while (false !== ($file = readdir($dh))) {
|
|
if ('.' === $file || '..' === $file || !is_dir($plugin_dir/$file)) {
|
|
continue;
|
|
}
|
|
$config_file = "$plugin_dir/$file/etc/config.json";
|
|
mergeConfig($config_file);
|
|
}
|
|
}
|
|
}
|
|
|
|
function getCustomerFromShortname()
|
|
{
|
|
global $configuration, $shortname;
|
|
return $configuration['project_manager']['projects'][$shortname]['customer'] ?? null;
|
|
}
|
|
|
|
function getProjectFromShortname()
|
|
{
|
|
global $configuration, $shortname;
|
|
return $configuration['project_manager']['projects'][$shortname]['project'] ?? null;
|
|
}
|
|
|
|
function parsePath()
|
|
{
|
|
global $configPath;
|
|
$parsedPath = '';
|
|
foreach (explode('.', $configPath) as $part) {
|
|
$parsedPath .= "['$part']";
|
|
}
|
|
return $parsedPath;
|
|
}
|
|
|
|
function is()
|
|
{
|
|
global $configuration, $shortname;
|
|
return eval("return isset(\$configuration['$shortname']".parsePath().");");
|
|
}
|
|
|
|
function get()
|
|
{
|
|
global $configuration, $shortname;
|
|
if (!is()) {
|
|
exit(1);
|
|
}
|
|
$return = eval("return \$configuration['$shortname']".parsePath().";");
|
|
if (is_array($return)) {
|
|
$echo = '';
|
|
foreach (array_keys($return) as $value) {
|
|
$echo .= '"'.$value.'" ';
|
|
}
|
|
$echo = trim($echo, ' ');
|
|
echo $echo;
|
|
exit;
|
|
}
|
|
echo $return;
|
|
}
|
|
|
|
function set()
|
|
{
|
|
global $configuration, $shortname, $value;
|
|
if (!is()) {
|
|
exit(1);
|
|
}
|
|
eval("\$configuration['$shortname']".parsePath()." = '$value';");
|
|
writeConfig();
|
|
}
|
|
|
|
function remove()
|
|
{
|
|
global $configuration, $shortname;
|
|
if (!is()) {
|
|
exit(1);
|
|
}
|
|
eval("unset \$configuration['$shortname']".parsePath().";");
|
|
writeConfig();
|
|
}
|
|
|
|
function writeConfig()
|
|
{
|
|
global $configuration, $shortname, $project_manager_dir;
|
|
$customer = getCustomerFromShortname();
|
|
$project = getProjectFromShortname();
|
|
|
|
foreach($configuration as $shortname => $data) {
|
|
if ('project_manager' === $shortname) {
|
|
$config_file = "$project_manager_dir/etc/config.json";
|
|
} elseif ('project' === $shortname) {
|
|
$config_file = "$project_manager_dir/data/$customer/$project/etc/config";
|
|
} else {
|
|
$config_file = "$project_manager_dir/data/$customer/$project/etc/plugins/$shortname/config";
|
|
}
|
|
file_put_contents($config_file, json_encode([$shortname => $data], JSON_PRETTY_PRINT));
|
|
}
|
|
}
|