Aleksander Machniak
2015-05-25 8042e13af6718bb6a2bd89066ccdb6700bed1029
Add --config and --type options to moduserprefs.sh script (#1490051)
3 files modified
50 ■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
bin/moduserprefs.sh 37 ●●●● patch | view | raw | blame | history
program/include/rcmail_utils.php 12 ●●●●● patch | view | raw | blame | history
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
bin/moduserprefs.sh
@@ -24,28 +24,45 @@
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']);
?>
program/include/rcmail_utils.php
@@ -327,8 +327,9 @@
     * @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 @@
            $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");