From 8042e13af6718bb6a2bd89066ccdb6700bed1029 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 25 May 2015 08:51:10 +0200 Subject: [PATCH] Add --config and --type options to moduserprefs.sh script (#1490051) --- CHANGELOG | 1 + bin/moduserprefs.sh | 37 +++++++++++++++++++++++--------- program/include/rcmail_utils.php | 12 ++++++++++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 27061716a..002b07b36 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Add --config and --type options to moduserprefs.sh script (#1490051) - Implemented memcache_debug and apc_debug options - Installer: Remove system() function use (#1490139) - Password plugin: Added 'kpasswd' driver by Peter Allgeyer diff --git a/bin/moduserprefs.sh b/bin/moduserprefs.sh index 09f73983a..858d76bce 100755 --- a/bin/moduserprefs.sh +++ b/bin/moduserprefs.sh @@ -24,28 +24,45 @@ require_once INSTALL_PATH.'program/include/clisetup.php'; function print_usage() { - print "Usage: moduserprefs.sh [--user=user-id] pref-name [pref-value|--delete]\n"; - print "--user User ID in local database\n"; - print "--delete Unset the given preference\n"; + print "Usage: moduserprefs.sh [options] pref-name [pref-value]\n"; + print "Options:\n"; + print " --user=user-id User ID in local database\n"; + print " --config=path Location of additional configuration file\n"; + print " --delete Unset the given preference\n"; + print " --type=type Pref-value type: int, bool, string\n"; } // get arguments -$args = rcube_utils::get_opt(array('u' => 'user', 'd' => 'delete')); +$args = rcube_utils::get_opt(array( + 'u' => 'user', + 'd' => 'delete', + 't' => 'type', + 'c' => 'config', +)); if ($_SERVER['argv'][1] == 'help') { - print_usage(); - exit; + print_usage(); + exit; } else if (empty($args[0]) || (!isset($args[1]) && !$args['delete'])) { - print "Missing required parameters.\n"; - print_usage(); - exit; + print "Missing required parameters.\n"; + print_usage(); + exit; } $pref_name = trim($args[0]); $pref_value = $args['delete'] ? null : trim($args[1]); -rcmail_utils::mod_pref($pref_name, $pref_value, $args['user']); +if ($pref_value === null) { + $args['type'] = null; +} + +if ($args['config']) { + $rcube = rcube::get_instance(); + $rcube->config->load_from_file($args['config']); +} + +rcmail_utils::mod_pref($pref_name, $pref_value, $args['user'], $args['type']); ?> diff --git a/program/include/rcmail_utils.php b/program/include/rcmail_utils.php index cc2ff73bd..f732a813c 100644 --- a/program/include/rcmail_utils.php +++ b/program/include/rcmail_utils.php @@ -327,8 +327,9 @@ class rcmail_utils * @param string Option name * @param string Option value * @param int Optional user identifier + * @param string Optional value type (bool, int, string) */ - public static function mod_pref($name, $value, $userid = null) + public static function mod_pref($name, $value, $userid = null, $type = 'string') { $db = self::db(); @@ -339,6 +340,15 @@ class rcmail_utils $query = '1=1'; } + $type = strtolower($type); + + if ($type == 'bool' || $type == 'boolean') { + $value = rcube_utils::get_boolean($value); + } + else if ($type == 'int' || $type == 'integer') { + $value = (int) $value; + } + // iterate over all users $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query");