ChangeSet ID: 26351 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2006/07/08 16:49:49
Modified files: cron : cleanup.php include : session.php
Log message: Chris Morgan cmorgan@alum.wpi.edu Add cron cleanup function to purge expired sessions from session_list table
Patch: http://cvs.winehq.org/patch.py?id=26351
Old revision New revision Changes Path 1.28 1.29 +32 -1 appdb/cron/cleanup.php 1.12 1.13 +7 -3 appdb/include/session.php
Index: appdb/cron/cleanup.php diff -u -p appdb/cron/cleanup.php:1.28 appdb/cron/cleanup.php:1.29 --- appdb/cron/cleanup.php:1.28 8 Jul 2006 21:49:49 -0000 +++ appdb/cron/cleanup.php 8 Jul 2006 21:49:49 -0000 @@ -72,9 +72,14 @@ notifyAdminsOfCleanupExecution($usersWar /* check to see if there are orphaned versions in the database */ orphanVersionCheck();
-/* check to see if we have any orphaned messages stuck in sessionMessages table */ +/* check and purge any orphaned messages stuck in sessionMessages table */ orphanSessionMessagesCheck();
+/* check and purge any expired sessions from the session_list table */ +orphanSessionListCheck(); + + +
/* Users that are unwarned and inactive since $iMonths */ function unwarnedAndInactiveSince($iMonths) @@ -197,3 +202,29 @@ function orphanSessionMessagesCheck() $sQuery = "DELETE from sessionMessages where TO_DAYS(NOW()) - TO_DAYS(time) > ?"; $hResult = query_parameters($sQuery, $iSessionMessageDayLimit); } + +/* this function checks to see if we have any orphaned sessions */ +/* sessions need to be expired or the session_list table will grow */ +/* by one row each time a user logs */ +function orphanSessionListCheck() +{ + /* get a count of the messages older than $iSessionListDayLimit */ + $sQuery = "SELECT count(*) as cnt from session_list where TO_DAYS(NOW()) - TO_DAYS(stamp) > ?"; + $hResult = query_parameters($sQuery, SESSION_DAYS_TO_EXPIRE + 2); + + $oRow = mysql_fetch_object($hResult); + $iMessages = $oRow->cnt; + + $sMsg = "Found ".$iMessages." sessions that have expired after ".(SESSION_DAYS_TO_EXPIRE + 2)." days\r\n"; + $sMsg.= " Purging these sessions.\r\n"; + + $sSubject = "Sessions expired\r\n"; + + $sEmail = User::get_notify_email_address_list(null, null); /* get list admins */ + if($sEmail) + mail_appdb($sEmail, $sSubject, $sMsg); + + /* purge the messages older than $iSessionMessageDayLimit */ + $sQuery = "DELETE from session_list where TO_DAYS(NOW()) - TO_DAYS(stamp) > ?"; + $hResult = query_parameters($sQuery, SESSION_DAYS_TO_EXPIRE + 2); +} Index: appdb/include/session.php diff -u -p appdb/include/session.php:1.12 appdb/include/session.php:1.13 --- appdb/include/session.php:1.12 8 Jul 2006 21:49:49 -0000 +++ appdb/include/session.php 8 Jul 2006 21:49:49 -0000 @@ -5,6 +5,9 @@ * sessions are stored in a mysql table */
+/* the number of days a session cookie is flaged to last */ +define(SESSION_DAYS_TO_EXPIRE, 2); + class session { // create session object @@ -28,9 +31,9 @@ class session array(&$this, "_gc") );
- // default lifetime on session cookie (90 days) + // default lifetime on session cookie (SESSION_DAYS_TO_EXPIRE days) session_set_cookie_params( - (60*60*24*90), + (60*60*24*SESSION_DAYS_TO_EXPIRE), '/' );
@@ -95,7 +98,8 @@ class session // clear old sessions (moved into a separate cron process) function _gc ($maxlifetime) { - query_parameters("DELETE FROM session_list WHERE to_days(now()) - to_days(stamp) >= 7"); + query_parameters("DELETE FROM session_list WHERE to_days(now()) - to_days(stamp) >= '?'", + SESSION_DAYS_TO_EXPIRE); return true; }