X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Finclude%2Frcube_user.php;h=19d08117d7e5ffa2f02de41cd77ce04936987af2;hb=a2dd2e41259a5e90016efcd7d083020b95e25527;hp=c764b186c2df094cfbf7f3577ebbb7efdd8d6ecf;hpb=4212156c5c79d2f58342feb0d3ed1893f177bcab;p=roundcube.git diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php index c764b18..19d0811 100644 --- a/program/include/rcube_user.php +++ b/program/include/rcube_user.php @@ -5,7 +5,7 @@ | program/include/rcube_user.inc | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland | + | Copyright (C) 2005-2010, The Roundcube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -16,7 +16,7 @@ | Author: Thomas Bruederli | +-----------------------------------------------------------------------+ - $Id: rcube_user.php 4290 2010-11-30 13:43:04Z alec $ + $Id: rcube_user.php 5165 2011-09-05 08:49:04Z thomasb $ */ @@ -29,16 +29,23 @@ */ class rcube_user { - public $ID = null; - public $data = null; - public $language = null; + public $ID; + public $data; + public $language; /** * Holds database connection. * * @var rcube_mdb2 */ - private $db = null; + private $db; + + /** + * rcmail object. + * + * @var rcmail + */ + private $rc; /** @@ -49,7 +56,8 @@ class rcube_user */ function __construct($id = null, $sql_arr = null) { - $this->db = rcmail::get_instance()->get_dbh(); + $this->rc = rcmail::get_instance(); + $this->db = $this->rc->get_dbh(); if ($id && !$sql_arr) { $sql_result = $this->db->query( @@ -82,8 +90,7 @@ class rcube_user } // if no domain was provided... if (empty($domain)) { - $rcmail = rcmail::get_instance(); - $domain = $rcmail->config->mail_domain($this->data['mail_host']); + $domain = $this->rc->config->mail_domain($this->data['mail_host']); } if ($part == 'domain') { @@ -110,8 +117,25 @@ class rcube_user if (!empty($this->language)) $prefs = array('language' => $this->language); - if ($this->ID && $this->data['preferences']) - $prefs += (array)unserialize($this->data['preferences']); + if ($this->ID) { + // Preferences from session (write-master is unavailable) + if (!empty($_SESSION['preferences'])) { + // Check last write attempt time, try to write again (every 5 minutes) + if ($_SESSION['preferences_time'] < time() - 5 * 60) { + $saved_prefs = unserialize($_SESSION['preferences']); + $this->rc->session->remove('preferences'); + $this->rc->session->remove('preferences_time'); + $this->save_prefs($saved_prefs); + } + else { + $this->data['preferences'] = $_SESSION['preferences']; + } + } + + if ($this->data['preferences']) { + $prefs += (array)unserialize($this->data['preferences']); + } + } return $prefs; } @@ -128,7 +152,7 @@ class rcube_user if (!$this->ID) return false; - $config = rcmail::get_instance()->config; + $config = $this->rc->config; $old_prefs = (array)$this->get_prefs(); // merge (partial) prefs array with existing settings @@ -154,11 +178,26 @@ class rcube_user $this->language = $_SESSION['language']; - if ($this->db->affected_rows()) { + // Update success + if ($this->db->affected_rows() !== false) { $config->set_user_prefs($a_user_prefs); $this->data['preferences'] = $save_prefs; + + if (isset($_SESSION['preferences'])) { + $this->rc->session->remove('preferences'); + $this->rc->session->remove('preferences_time'); + } return true; } + // Update error, but we are using replication (we have read-only DB connection) + // and we are storing session not in the SQL database + // we can store preferences in session and try to write later (see get_prefs()) + else if ($this->db->is_replicated() && $config->get('session_storage', 'db') != 'db') { + $_SESSION['preferences'] = $save_prefs; + $_SESSION['preferences_time'] = time(); + $config->set_user_prefs($a_user_prefs); + $this->data['preferences'] = $save_prefs; + } return false; } @@ -288,7 +327,7 @@ class rcube_user // we'll not delete last identity if ($sql_arr['ident_count'] <= 1) - return false; + return -1; $this->db->query( "UPDATE ".get_table_name('identities'). @@ -359,16 +398,15 @@ class rcube_user $dbh = rcmail::get_instance()->get_dbh(); // use BINARY (case-sensitive) comparison on MySQL, other engines are case-sensitive - $prefix = preg_match('/^mysql/', $dbh->db_provider) ? 'BINARY ' : ''; + $mod = preg_match('/^mysql/', $dbh->db_provider) ? 'BINARY' : ''; // query for matching user name - $query = "SELECT * FROM ".get_table_name('users')." WHERE mail_host = ? AND %s = ?"; - - $sql_result = $dbh->query(sprintf($query, $prefix.'username'), $host, $user); + $query = "SELECT * FROM ".get_table_name('users')." WHERE mail_host = ? AND %s = $mod ?"; + $sql_result = $dbh->query(sprintf($query, 'username'), $host, $user); // query for matching alias if (!($sql_arr = $dbh->fetch_assoc($sql_result))) { - $sql_result = $dbh->query(sprintf($query, $prefix.'alias'), $host, $user); + $sql_result = $dbh->query(sprintf($query, 'alias'), $host, $user); $sql_arr = $dbh->fetch_assoc($sql_result); } @@ -399,7 +437,7 @@ class rcube_user } $data = $rcmail->plugins->exec_hook('user_create', - array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email)); + array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email, 'host'=>$host)); // plugin aborted this operation if ($data['abort'])