mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
using new admin_cmd_config to log and document config changes
This commit is contained in:
parent
b1b31e2b0b
commit
1115db478f
77
admin/inc/class.admin_cmd_config.inc.php
Normal file
77
admin/inc/class.admin_cmd_config.inc.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* EGroupware admin - change EGw configuration
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <rb@egroupware.org>
|
||||
* @package setup
|
||||
* @copyright (c) 2018 by Ralf Becker <rb@egroupware.org>
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
*/
|
||||
|
||||
use EGroupware\Api;
|
||||
|
||||
/**
|
||||
* setup command: change EGw configuration
|
||||
*
|
||||
* @property-read string $app app whos config to change
|
||||
* @property-read array $set config data to set, value of null or "" to remove
|
||||
* @property-read array $old old values to record
|
||||
*/
|
||||
class admin_cmd_config extends admin_cmd
|
||||
{
|
||||
/**
|
||||
* Allow to run this command via setup-cli
|
||||
*/
|
||||
//const SETUP_CLI_CALLABLE = true; // need to check how to parse arguments
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|string $data data array or app whos config to change
|
||||
* @param array $set =null config data to set, value of null or "" to remove
|
||||
* @param array $old =null old values to record
|
||||
* @param array $other =null values for keys "requested", "requested_email", "comment", etc
|
||||
*/
|
||||
function __construct($data, array $set=null, array $old=null, $other=null)
|
||||
{
|
||||
if (!is_array($data))
|
||||
{
|
||||
$data = array(
|
||||
'app' => $data,
|
||||
'set' => $set,
|
||||
'old' => $old,
|
||||
)+(array)$other;
|
||||
}
|
||||
//echo __CLASS__.'::__construct()'; _debug_array($domain);
|
||||
admin_cmd::__construct($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* run the command: write the configuration to the database
|
||||
*
|
||||
* @param boolean $check_only =false only run the checks (and throw the exceptions), but not the command itself
|
||||
* @return string success message
|
||||
* @throws Exception(lang('Wrong credentials to access the header.inc.php file!'),2);
|
||||
* @throws Exception('header.inc.php not found!');
|
||||
*/
|
||||
protected function exec($check_only=false)
|
||||
{
|
||||
if ($check_only)
|
||||
{
|
||||
return true; // no specific checks exist
|
||||
}
|
||||
|
||||
$config = new Api\Config($this->app);
|
||||
$config->read_repository();
|
||||
|
||||
// store the config
|
||||
foreach($this->set as $name => $value)
|
||||
{
|
||||
$config->value($name, $value);
|
||||
}
|
||||
$config->save_repository();
|
||||
|
||||
return lang('Configuration changed.');
|
||||
}
|
||||
}
|
@ -179,12 +179,18 @@ class admin_config
|
||||
unset($GLOBALS['egw_info']['server']['found_validation_hook']);
|
||||
}
|
||||
|
||||
// compute real changes and their old values (null for removals)
|
||||
$modifications = array_diff_assoc($c->config_data, $old);
|
||||
$removals = array_diff_assoc($old, $c->config_data);
|
||||
if ($modifications || $removals)
|
||||
$set = array_merge(array_fill_keys(array_keys($removals), null), $modifications);
|
||||
$old = array_filter($old, function($key) use ($set)
|
||||
{
|
||||
$c->save_repository();
|
||||
$msg = lang('Configuration saved.');
|
||||
return array_key_exists($key, $set);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
if ($set)
|
||||
{
|
||||
$cmd = new admin_cmd_config($config_appname, $set, $old, $_content['admin_cmd']);
|
||||
$msg = $cmd->run();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user