diff options
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/rcube_imap.php | 6 | ||||
-rw-r--r-- | program/include/session.inc | 64 |
2 files changed, 36 insertions, 34 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index d8845cc74..c3d599180 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2146,7 +2146,7 @@ class rcube_imap { $this->db->query( "UPDATE ".get_table_name('cache')." - SET created=".$this->db->now().", data=?, session_id=? + SET created=". $this->db->fromunixtime(time()).", data=?, session_id=? WHERE user_id=? AND cache_key=?", $data, @@ -2160,7 +2160,7 @@ class rcube_imap $this->db->query( "INSERT INTO ".get_table_name('cache')." (created, user_id, cache_key, data, session_id) - VALUES (".$this->db->now().", ?, ?, ?, ?)", + VALUES (".$this->db->fromunixtime(time()).", ?, ?, ?, ?)", $_SESSION['user_id'], $key, $data, @@ -2374,7 +2374,7 @@ class rcube_imap $this->db->query( "INSERT INTO ".get_table_name('messages')." (user_id, del, cache_key, created, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers, structure) - VALUES (?, 0, ?, ".$this->db->now().", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)", + VALUES (?, 0, ?, ".$this->db->fromunixtime(time()).", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)", $_SESSION['user_id'], $key, $index, diff --git a/program/include/session.inc b/program/include/session.inc index d6486a43a..21d22ab28 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -75,10 +75,12 @@ function rcube_sess_write($key, $vars) WHERE sess_id=?", $key); + $now = $DB->fromunixtime(time()); + if ($DB->num_rows($sql_result)) { $DB->query( "UPDATE " . get_table_name('session') . " - SET vars=?, changed=" . $DB->now() . " + SET vars=?, changed= " . $now . " WHERE sess_id=?", $vars, $key); @@ -87,7 +89,7 @@ function rcube_sess_write($key, $vars) $DB->query( "INSERT INTO " . get_table_name('session') . " (sess_id, vars, ip, created, changed) - VALUES (?, ?, ?, ".$DB->now().", ".$DB->now().")", + VALUES (?, ?, ?, " . $now . ", " . $now .")", $key, $vars, (string)$_SERVER['REMOTE_ADDR']); @@ -107,12 +109,13 @@ function rcube_sess_destroy($key) return false; } + $DB->query("DELETE FROM " . get_table_name('session') . " WHERE sess_id=?", $key); + // delete session entries in cache table - if ($rcmail->config->get('enable_caching')) { + // on databases wthout foreign keys + if ($rcmail->config->get('enable_caching') && $DB->db_provider != 'pgsql') { $DB->query("DELETE FROM " . get_table_name('cache') . " WHERE session_id=?", $key); } - - $DB->query("DELETE FROM " . get_table_name('session') . " WHERE sess_id=?", $key); return true; } @@ -128,40 +131,39 @@ function rcube_sess_gc($maxlifetime) return false; } + $now = $DB->fromunixtime(time() - $maxlifetime); + + // delete session entries in cache table if ($rcmail->config->get('enable_caching')) { - // get all expired sessions - $sql_result = $DB->query( - "SELECT sess_id - FROM " . get_table_name('session') . " - WHERE " . $DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed') . " > ?", - $maxlifetime); - - $exp_sessions = array(); - while ($sql_arr = $DB->fetch_assoc($sql_result)) { - $exp_sessions[] = $sql_arr['sess_id']; - } - if (sizeof($exp_sessions)) { - $exp_sessions = "'" . join("','", $exp_sessions) . "'"; - // delete session cache records - $DB->query("DELETE FROM " . get_table_name('cache') . " - WHERE session_id IN (" . $exp_sessions . ")"); + // on databases wthout foreign keys... + if($DB->db_provider != 'pgsql') { - // delete session records - $DB->query("DELETE FROM " . get_table_name('session') . " - WHERE sess_id IN (" . $exp_sessions . ")"); - } + // get all expired sessions + $sql_result = $DB->query( + "SELECT sess_id FROM " . get_table_name('session') . " + WHERE changed < " . $now); + $exp_sessions = array(); + while ($sql_arr = $DB->fetch_assoc($sql_result)) { + $exp_sessions[] = $sql_arr['sess_id']; + } + + if (sizeof($exp_sessions)) { + $exp_sessions = "'" . join("','", $exp_sessions) . "'"; + // delete session cache records + $DB->query("DELETE FROM " . get_table_name('cache') . " + WHERE session_id IN (" . $exp_sessions . ")"); + } + } // also run message cache GC rcmail_message_cache_gc(); - - } else { - // just delete all expired sessions - $DB->query("DELETE FROM " . get_table_name('session') . " - WHERE " . $DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed') . " > ?", - $maxlifetime); } + // just delete all expired sessions + $DB->query("DELETE FROM " . get_table_name('session') . " + WHERE changed < " . $now); + rcmail_temp_gc(); return true; |