Skip to content

Commit bfe6570

Browse files
committed
Fix issues when using moduserprefs.sh without --user argument (#1490399)
Conflicts: program/include/rcmail_utils.php
1 parent 7fdc341 commit bfe6570

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG Roundcube Webmail
1212
- Fix security issue in contact photo handling (#1490379)
1313
- Fix bug where database_attachments_cache setting was not working
1414
- Fix attached file path unsetting in database_attachments plugin (#1490393)
15+
- Fix issues when using moduserprefs.sh without --user argument (#1490399)
1516

1617
RELEASE 1.0.5
1718
-------------

bin/moduserprefs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
7171
$prefs[$pref_name] = $pref_value;
7272

7373
if ($prefs != $old_prefs) {
74-
$user->save_prefs($prefs);
74+
$user->save_prefs($prefs, true);
7575
echo "saved.\n";
7676
}
7777
else {

program/lib/Roundcube/rcube_user.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ function get_prefs()
158158
* Write the given user prefs to the user's record
159159
*
160160
* @param array $a_user_prefs User prefs to save
161+
* @param bool $no_session Simplified language/preferences handling
162+
*
161163
* @return boolean True on success, False on failure
162164
*/
163-
function save_prefs($a_user_prefs)
165+
function save_prefs($a_user_prefs, $no_session = false)
164166
{
165167
if (!$this->ID)
166168
return false;
@@ -187,33 +189,40 @@ function save_prefs($a_user_prefs)
187189
}
188190

189191
$save_prefs = serialize($save_prefs);
192+
if (!$no_session) {
193+
$this->language = $_SESSION['language'];
194+
}
190195

191196
$this->db->query(
192197
"UPDATE ".$this->db->table_name('users').
193198
" SET preferences = ?".
194199
", language = ?".
195200
" WHERE user_id = ?",
196201
$save_prefs,
197-
$_SESSION['language'],
202+
$this->language,
198203
$this->ID);
199204

200-
$this->language = $_SESSION['language'];
201-
202205
// Update success
203206
if ($this->db->affected_rows() !== false) {
204-
$config->set_user_prefs($a_user_prefs);
205207
$this->data['preferences'] = $save_prefs;
206208

207-
if (isset($_SESSION['preferences'])) {
208-
$this->rc->session->remove('preferences');
209-
$this->rc->session->remove('preferences_time');
209+
if (!$no_session) {
210+
$config->set_user_prefs($a_user_prefs);
211+
212+
if (isset($_SESSION['preferences'])) {
213+
$this->rc->session->remove('preferences');
214+
$this->rc->session->remove('preferences_time');
215+
}
210216
}
217+
211218
return true;
212219
}
213220
// Update error, but we are using replication (we have read-only DB connection)
214221
// and we are storing session not in the SQL database
215222
// we can store preferences in session and try to write later (see get_prefs())
216-
else if ($this->db->is_replicated() && $config->get('session_storage', 'db') != 'db') {
223+
else if (!$no_session && $this->db->is_replicated()
224+
&& $config->get('session_storage', 'db') != 'db'
225+
) {
217226
$_SESSION['preferences'] = $save_prefs;
218227
$_SESSION['preferences_time'] = time();
219228
$config->set_user_prefs($a_user_prefs);

0 commit comments

Comments
 (0)