/**
* Table Definition for session
*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2009, Control Yourself, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ static function logdeb($msg)
+ {
+ if (common_config('sessions', 'debug')) {
+ common_debug("Session: " . $msg);
+ }
+ }
+
static function open($save_path, $session_name)
{
return true;
static function read($id)
{
+ self::logdeb("Fetching session '$id'");
+
$session = Session::staticGet('id', $id);
if (empty($session)) {
static function write($id, $session_data)
{
+ self::logdeb("Writing session '$id'");
+
$session = Session::staticGet('id', $id);
if (empty($session)) {
return $session->insert();
} else {
- $session->session_data = $session_data;
+ if (strcmp($session->session_data, $session_data) == 0) {
+ self::logdeb("Not writing session '$id'; unchanged");
+ return true;
+ } else {
+ self::logdeb("Session '$id' data changed; updating");
+
+ $orig = clone($session);
- return $session->update();
+ $session->session_data = $session_data;
+
+ return $session->update($orig);
+ }
}
}
static function destroy($id)
{
+ self::logdeb("Deleting session $id");
+
$session = Session::staticGet('id', $id);
if (!empty($session)) {
static function gc($maxlifetime)
{
- $epoch = time() - $maxlifetime;
+ self::logdeb("garbage collection (maxlifetime = $maxlifetime)");
- $qry = 'DELETE FROM session ' .
- 'WHERE modified < "'.$epoch.'"';
+ $epoch = common_sql_date(time() - $maxlifetime);
+
+ $ids = array();
$session = new Session();
+ $session->whereAdd('modified < "'.$epoch.'"');
+ $session->selectAdd();
+ $session->selectAdd('id');
+
+ $session->find();
- $session->query($qry);
+ while ($session->fetch()) {
+ $ids[] = $session->id;
+ }
+
+ $session->free();
+
+ foreach ($ids as $id) {
+ self::destroy($id);
+ }
}
static function setSaveHandler()
{
- session_set_save_handler('Session::open', 'Session::close', 'Session::read',
- 'Session::write', 'Session::destroy', 'Session::gc');
+ self::logdeb("setting save handlers");
+ $result = session_set_save_handler('Session::open', 'Session::close', 'Session::read',
+ 'Session::write', 'Session::destroy', 'Session::gc');
+ self::logdeb("save handlers result = $result");
+ return $result;
}
}