]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Session.php
Merge branch '0.8.x' of git@gitorious.org:statusnet/mainline into 0.8.x
[quix0rs-gnu-social.git] / classes / Session.php
index 5c48e4aa90bae9f80bf0eafb0998b44f05439c6f..d641edbbe408af12c87bdcd32a416672429d2eeb 100644 (file)
@@ -2,8 +2,8 @@
 /**
  * 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
@@ -19,7 +19,7 @@
  * 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';
 
@@ -42,7 +42,9 @@ class Session extends Memcached_DataObject
 
     static function logdeb($msg)
     {
-        common_debug("Session: " . $msg);
+        if (common_config('sessions', 'debug')) {
+            common_debug("Session: " . $msg);
+        }
     }
 
     static function open($save_path, $session_name)
@@ -104,16 +106,26 @@ class Session extends Memcached_DataObject
     {
         self::logdeb("garbage collection (maxlifetime = $maxlifetime)");
 
-        $epoch = time() - $maxlifetime;
+        $epoch = common_sql_date(time() - $maxlifetime);
 
-        $qry = 'DELETE FROM session ' .
-          'WHERE modified < "'.$epoch.'"';
+        $ids = array();
 
         $session = new Session();
+        $session->whereAdd('modified < "'.$epoch.'"');
+        $session->selectAdd();
+        $session->selectAdd('id');
+
+        $session->find();
 
-        $result = $session->query($qry);
+        while ($session->fetch()) {
+            $ids[] = $session->id;
+        }
 
-        self::logdeb("garbage collection result = $result");
+        $session->free();
+
+        foreach ($ids as $id) {
+            self::destroy($id);
+        }
     }
 
     static function setSaveHandler()