getting admin_cmd_config history finished:

- deprecate app="phpgwapi" and appname, using now "store_as_api" and changed app
- update script to fix database
- use "config" hook to load application specific options
This commit is contained in:
Ralf Becker 2019-03-20 11:54:30 +01:00
parent a33c3a60b7
commit 858f2c0119
5 changed files with 72 additions and 18 deletions

View File

@ -1378,11 +1378,13 @@ abstract class admin_cmd
*/ */
function get_change_widgets() function get_change_widgets()
{ {
static $selectboxes = ['select', 'listbox', 'menupopup', 'taglist'];
$widgets = []; $widgets = [];
$last_select = null; $last_select = null;
if (($tpl = $this->get_etemplate())) if (($tpl = $this->get_etemplate()))
{ {
$tpl->run(function($cname, $expand, $widget) use (&$widgets, &$last_select) $tpl->run(function($cname, $expand, $widget) use (&$widgets, &$last_select, $selectboxes)
{ {
switch($widget->type) switch($widget->type)
{ {
@ -1391,7 +1393,7 @@ abstract class admin_cmd
case 'grid': case 'columns': case 'column': case 'rows': case 'row': case 'grid': case 'columns': case 'column': case 'rows': case 'row':
case 'template': case 'tabbox': case 'tabs': case 'tab': case 'template': case 'tabbox': case 'tabs': case 'tab':
// No need for these // No need for these
case 'textbox': case 'int': case 'float': case 'select': case 'textbox': case 'int': case 'float':
// ignore widgets that can't go in the historylog // ignore widgets that can't go in the historylog
case 'button': case 'buttononly': case 'taglist-thumbnail': case 'button': case 'buttononly': case 'taglist-thumbnail':
break; break;
@ -1414,7 +1416,7 @@ abstract class admin_cmd
if (!empty($widget->id)) if (!empty($widget->id))
{ {
$widgets[$widget->id] = $widget->type; $widgets[$widget->id] = $widget->type;
if (in_array($widget->type, ['select'])) if (in_array($widget->type, $selectboxes))
{ {
$last_select = $widget->id; $last_select = $widget->id;
} }
@ -1423,6 +1425,9 @@ abstract class admin_cmd
} }
unset($cname, $expand); unset($cname, $expand);
}, ['', []]); }, ['', []]);
// remove pure selectboxes, as they would show nothing without having options
$widgets = array_diff($widgets, $selectboxes);
} }
return $widgets; return $widgets;
} }

View File

@ -14,8 +14,8 @@ use EGroupware\Api;
/** /**
* setup command: change EGw configuration * setup command: change EGw configuration
* *
* @property-read string $app app whos config to change (egw_config.config_app) * @property-read string $app app whos config to change
* @property-read string $appname app name whos config is changed (some apps store their config under app="phpgwapi") * @property-read boolean $store_as_api some apps store their config under app="phpgwapi"
* @property-read array $set config data to set, value of null or "" to remove * @property-read array $set config data to set, value of null or "" to remove
* @property-read array $old old values to record * @property-read array $old old values to record
*/ */
@ -26,6 +26,11 @@ class admin_cmd_config extends admin_cmd
*/ */
//const SETUP_CLI_CALLABLE = true; // need to check how to parse arguments //const SETUP_CLI_CALLABLE = true; // need to check how to parse arguments
/**
* Name to use if $this->store_as_api is set
*/
const STORE_AS_API = 'phpgwapi';
/** /**
* Constructor * Constructor
* *
@ -33,8 +38,9 @@ class admin_cmd_config extends admin_cmd
* @param array $set =null config data to set, value of null or "" to remove * @param array $set =null config data to set, value of null or "" to remove
* @param array $old =null old values to record * @param array $old =null old values to record
* @param array $other =null values for keys "requested", "requested_email", "comment", etc * @param array $other =null values for keys "requested", "requested_email", "comment", etc
* @param boolean $store_as_api =false true: store under "phpgwapi"
*/ */
function __construct($data, array $set=null, array $old=null, $other=null) function __construct($data, array $set=null, array $old=null, array $other=null, $store_as_api=false)
{ {
if (!is_array($data)) if (!is_array($data))
{ {
@ -42,8 +48,18 @@ class admin_cmd_config extends admin_cmd
'app' => $data, 'app' => $data,
'set' => $set, 'set' => $set,
'old' => $old, 'old' => $old,
'store_as_api' => $store_as_api,
)+(array)$other; )+(array)$other;
} }
// fix depreated use of app="phpwapi" or appname!=app
if ($data['app'] === self::STORE_AS_API || !empty($data['appname']))
{
$data['store_as_api'] = true;
$data['app'] = !empty($data['appname']) ? $data['appname'] : 'setup';
unset($data['appname']);
}
//echo __CLASS__.'::__construct()'; _debug_array($domain); //echo __CLASS__.'::__construct()'; _debug_array($domain);
admin_cmd::__construct($data); admin_cmd::__construct($data);
} }
@ -63,7 +79,7 @@ class admin_cmd_config extends admin_cmd
return true; // no specific checks exist return true; // no specific checks exist
} }
$config = new Api\Config($this->app); $config = new Api\Config($this->store_as_api ? self::STORE_AS_API : $this->app);
$config->read_repository(); $config->read_repository();
// store the config // store the config
@ -83,8 +99,7 @@ class admin_cmd_config extends admin_cmd
*/ */
function __tostring() function __tostring()
{ {
return lang('%1 site configuration', return lang('site configuration').': '.lang($this->app);
lang($this->appname ? $this->appname : $this->app));
} }
/** /**
@ -94,7 +109,7 @@ class admin_cmd_config extends admin_cmd
*/ */
function get_etemplate_name() function get_etemplate_name()
{ {
return ($this->appname ? $this->appname : $this->app).'.config'; return $this->app.'.config';
} }
/** /**
@ -127,11 +142,20 @@ class admin_cmd_config extends admin_cmd
function get_change_widgets() function get_change_widgets()
{ {
$widgets = []; $widgets = [];
// get selectbox options from "config" hook
$ret = Api\Hooks::single('config', $this->app);
if (is_array($ret) && isset($ret['sel_options']))
{
$widgets = $ret['sel_options'];
}
// get widgets from eTemplate (with newsettings namespace!)
foreach(parent::get_change_widgets() as $id => $widget) foreach(parent::get_change_widgets() as $id => $widget)
{ {
if (strpos($id, 'newsettings[') === 0) if (strpos($id, 'newsettings[') === 0)
{ {
$widgets[substr($id, 12, -1)] = $widget; $widgets[$id=substr($id, 12, -1)] = $widget;
} }
} }
return $widgets; return $widgets;

View File

@ -195,8 +195,8 @@ class admin_config
}, ARRAY_FILTER_USE_KEY); }, ARRAY_FILTER_USE_KEY);
if ($set) if ($set)
{ {
$cmd = new admin_cmd_config($config_appname, $set, $old, $cmd = new admin_cmd_config($_appname, $set, $old,
(array)$_content['admin_cmd']+array('appname' => $_appname)); (array)$_content['admin_cmd'], $config_appname === 'phpgwapi');
$msg = $cmd->run(); $msg = $cmd->run();
} }
else else

View File

@ -9,7 +9,7 @@
*/ */
$setup_info['admin']['name'] = 'admin'; $setup_info['admin']['name'] = 'admin';
$setup_info['admin']['version'] = '18.1'; $setup_info['admin']['version'] = '18.1.001';
$setup_info['admin']['app_order'] = 1; $setup_info['admin']['app_order'] = 1;
$setup_info['admin']['tables'] = array('egw_admin_queue','egw_admin_remote'); $setup_info['admin']['tables'] = array('egw_admin_queue','egw_admin_remote');
$setup_info['admin']['enable'] = 1; $setup_info['admin']['enable'] = 1;
@ -18,7 +18,7 @@ $setup_info['admin']['index'] = 'admin.admin_ui.index&ajax=true';
$setup_info['admin']['author'] = $setup_info['admin']['maintainer'] = array( $setup_info['admin']['author'] = $setup_info['admin']['maintainer'] = array(
'name' => 'EGroupware GmbH', 'name' => 'EGroupware GmbH',
'email' => 'info@egroupware.org', 'email' => 'info@egroupware.org',
'url' => 'http://www.egroupware.org' 'url' => 'https://www.egroupware.org'
); );
$setup_info['admin']['license'] = 'GPL'; $setup_info['admin']['license'] = 'GPL';
@ -42,4 +42,3 @@ $setup_info['admin']['depends'][] = array(
'appname' => 'api', 'appname' => 'api',
'versions' => Array('17.1') 'versions' => Array('17.1')
); );

View File

@ -11,8 +11,6 @@
* @subpackage setup * @subpackage setup
*/ */
use EGroupware\Api;
function admin_upgrade1_2() function admin_upgrade1_2()
{ {
return $GLOBALS['setup_info']['admin']['currentver'] = '1.4'; return $GLOBALS['setup_info']['admin']['currentver'] = '1.4';
@ -243,3 +241,31 @@ function admin_upgrade17_1()
return $GLOBALS['setup_info']['admin']['currentver'] = '18.1'; return $GLOBALS['setup_info']['admin']['currentver'] = '18.1';
} }
/**
* Update admin_cmd_config to use "store_as_api" instead of "app"="phpgwapi" and "appname"
*
* @return string
*/
function admin_upgrade18_1()
{
// fill cmd_account/app from
foreach($GLOBALS['egw_setup']->db->select('egw_admin_queue', 'cmd_id,cmd_app,cmd_data', array(
'cmd_app' => 'phpgwapi',
'cmd_type' => 'admin_cmd_config',
), __LINE__, __FILE__, false, '', 'admin') as $row)
{
$data = json_php_unserialize($row['cmd_data']);
$data['store_as_api'] = $row['cmd_app'] === 'phpgwapi';
$row['cmd_app'] = !empty($data['appname']) ? $data['appname'] : 'setup';
unset($data['appname']);
$cmd_id = $row['cmd_id'];
unset($row['cmd_id']);
$row['cmd_data'] = json_encode($data);
$GLOBALS['egw_setup']->db->update('egw_admin_queue', $row,
array('cmd_id' => $cmd_id), __LINE__, __FILE__, 'admin');
}
return $GLOBALS['setup_info']['admin']['currentver'] = '18.1.001';
}