commit | author | age
|
fa9819
|
1 |
#!/usr/bin/env php |
TB |
2 |
<?php |
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
f23ef1
|
5 |
| bin/moduserprefs.sh | |
fa9819
|
6 |
| | |
TB |
7 |
| This file is part of the Roundcube Webmail client | |
|
8 |
| Copyright (C) 2012, The Roundcube Dev Team | |
|
9 |
| | |
|
10 |
| Licensed under the GNU General Public License version 3 or | |
|
11 |
| any later version with exceptions for skins & plugins. | |
|
12 |
| See the README file for a full license statement. | |
|
13 |
| | |
|
14 |
| PURPOSE: | |
|
15 |
| Bulk-change settings stored in user preferences | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
18 |
+-----------------------------------------------------------------------+ |
|
19 |
*/ |
|
20 |
|
0ea079
|
21 |
define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); |
fa9819
|
22 |
|
TB |
23 |
require_once INSTALL_PATH.'program/include/clisetup.php'; |
|
24 |
|
|
25 |
function print_usage() |
|
26 |
{ |
|
27 |
print "Usage: moduserprefs.sh [--user=user-id] pref-name [pref-value|--delete]\n"; |
|
28 |
print "--user User ID in local database\n"; |
|
29 |
print "--delete Unset the given preference\n"; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
// get arguments |
6585e8
|
34 |
$args = rcube_utils::get_opt(array('u' => 'user', 'd' => 'delete')); |
fa9819
|
35 |
|
TB |
36 |
if ($_SERVER['argv'][1] == 'help') { |
|
37 |
print_usage(); |
|
38 |
exit; |
|
39 |
} |
|
40 |
else if (empty($args[0]) || (!isset($args[1]) && !$args['delete'])) { |
|
41 |
print "Missing required parameters.\n"; |
|
42 |
print_usage(); |
|
43 |
exit; |
|
44 |
} |
|
45 |
|
|
46 |
$pref_name = trim($args[0]); |
|
47 |
$pref_value = $args['delete'] ? null : trim($args[1]); |
|
48 |
|
|
49 |
// connect to DB |
dcc446
|
50 |
$rcmail = rcube::get_instance(); |
fa9819
|
51 |
|
TB |
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']) |
34a090
|
61 |
$query = '`user_id` = ' . intval($args['user']); |
fa9819
|
62 |
|
TB |
63 |
// iterate over all users |
34a090
|
64 |
$sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query"); |
fa9819
|
65 |
while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) { |
TB |
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); |
|
75 |
echo "saved.\n"; |
|
76 |
} |
|
77 |
else { |
|
78 |
echo "nothing changed.\n"; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
?> |