comparison bin/moduserprefs.sh @ 8:bf99236cc5cd default tip

try to recover from upgrade fail
author Charlie Root
date Sat, 29 Dec 2018 07:07:34 -0500
parents 4681f974d28b
children
comparison
equal deleted inserted replaced
7:65fd7d441cf1 8:bf99236cc5cd
3 /* 3 /*
4 +-----------------------------------------------------------------------+ 4 +-----------------------------------------------------------------------+
5 | bin/moduserprefs.sh | 5 | bin/moduserprefs.sh |
6 | | 6 | |
7 | This file is part of the Roundcube Webmail client | 7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2012, The Roundcube Dev Team | 8 | Copyright (C) 2012-2015, The Roundcube Dev Team |
9 | | 9 | |
10 | Licensed under the GNU General Public License version 3 or | 10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. | 11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. | 12 | See the README file for a full license statement. |
13 | | 13 | |
22 22
23 require_once INSTALL_PATH.'program/include/clisetup.php'; 23 require_once INSTALL_PATH.'program/include/clisetup.php';
24 24
25 function print_usage() 25 function print_usage()
26 { 26 {
27 print "Usage: moduserprefs.sh [--user=user-id] pref-name [pref-value|--delete]\n"; 27 print "Usage: moduserprefs.sh [options] pref-name [pref-value]\n";
28 print "--user User ID in local database\n"; 28 print "Options:\n";
29 print "--delete Unset the given preference\n"; 29 print " --user=user-id User ID in local database\n";
30 print " --config=path Location of additional configuration file\n";
31 print " --delete Unset the given preference\n";
32 print " --type=type Pref-value type: int, bool, string\n";
30 } 33 }
31 34
32 35
33 // get arguments 36 // get arguments
34 $args = rcube_utils::get_opt(array('u' => 'user', 'd' => 'delete')); 37 $args = rcube_utils::get_opt(array(
38 'u' => 'user',
39 'd' => 'delete:bool',
40 't' => 'type',
41 'c' => 'config',
42 ));
35 43
36 if ($_SERVER['argv'][1] == 'help') { 44 if ($_SERVER['argv'][1] == 'help') {
37 print_usage(); 45 print_usage();
38 exit; 46 exit;
39 } 47 }
40 else if (empty($args[0]) || (!isset($args[1]) && !$args['delete'])) { 48 else if (empty($args[0]) || (empty($args[1]) && empty($args['delete']))) {
41 print "Missing required parameters.\n"; 49 print "Missing required parameters.\n";
42 print_usage(); 50 print_usage();
43 exit; 51 exit;
44 } 52 }
45 53
46 $pref_name = trim($args[0]); 54 $pref_name = trim($args[0]);
47 $pref_value = $args['delete'] ? null : trim($args[1]); 55 $pref_value = $args['delete'] ? null : trim($args[1]);
48 56
49 // connect to DB 57 if ($pref_value === null) {
50 $rcmail = rcube::get_instance(); 58 $args['type'] = null;
51
52 $db = $rcmail->get_dbh();
53 $db->db_connect('w');
54
55 if (!$db->is_connected() || $db->is_error())
56 die("No DB connection\n" . $db->is_error());
57
58 $query = '1=1';
59
60 if ($args['user'])
61 $query = '`user_id` = ' . intval($args['user']);
62
63 // iterate over all users
64 $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query");
65 while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
66 echo "Updating prefs for user " . $sql_arr['user_id'] . "...";
67
68 $user = new rcube_user($sql_arr['user_id'], $sql_arr);
69 $prefs = $old_prefs = $user->get_prefs();
70
71 $prefs[$pref_name] = $pref_value;
72
73 if ($prefs != $old_prefs) {
74 $user->save_prefs($prefs, true);
75 echo "saved.\n";
76 }
77 else {
78 echo "nothing changed.\n";
79 }
80 } 59 }
81 60
61 if ($args['config']) {
62 $rcube = rcube::get_instance();
63 $rcube->config->load_from_file($args['config']);
64 }
65
66 rcmail_utils::mod_pref($pref_name, $pref_value, $args['user'], $args['type']);
67
82 ?> 68 ?>