ChangeSet ID: 26197
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner(a)winehq.org 2006/07/05 23:39:02
Modified files:
cron : cleanup.php
Log message:
Chris Morgan <cmorgan(a)alum.wpi.edu>
Purge orphaned messages from sessionMessages that are older than 1 day after notifying admins
of the number of orphaned messages. We currently have
over 150k messages stuck in this table with the earliest dating back to 2004.
We need to ensure that this doesn't occur again and that we can detect leaked
messages as these represent bugs in the appdb code.
Patch: http://cvs.winehq.org/patch.py?id=26197
Old revision New revision Changes Path
1.26 1.27 +32 -2 appdb/cron/cleanup.php
Index: appdb/cron/cleanup.php
diff -u -p appdb/cron/cleanup.php:1.26 appdb/cron/cleanup.php:1.27
--- appdb/cron/cleanup.php:1.26 6 Jul 2006 4:39: 2 -0000
+++ appdb/cron/cleanup.php 6 Jul 2006 4:39: 2 -0000
@@ -72,7 +72,8 @@ 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 */
+orphanSessionMessagesCheck();
/* Users that are unwarned and inactive since $iMonths */
@@ -149,7 +150,7 @@ function orphanVersionCheck()
$found_orphans = false;
$sMsg = "Found these orphaned versions in the database with\r\n";
- $sMSg = "this sql command '".$sQuery."'\r\n";
+ $sMsg.= "this sql command '".$sQuery."'\r\n";
/* don't report anything if no orphans are found */
if(mysql_num_rows($hResult) == 0)
@@ -167,3 +168,32 @@ function orphanVersionCheck()
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
+
+/* this function checks to see if we have any orphaned session messages */
+/* These orphaned messages are an indication that we've put a message into */
+/* the system without displaying it and it becomes effectively lost forever */
+/* so we'll want to purge them here after reporting how many we have */
+function orphanSessionMessagesCheck()
+{
+ $iSessionMessageDayLimit = 1; /* the number of days a session message must be stuck before being purges */
+
+ /* get a count of the messages older than $iSessionMessageDayLimit */
+ $sQuery = "SELECT count(*) as cnt from sessionMessages where TO_DAYS(NOW()) - TO_DAYS(time) > ?";
+ $hResult = query_parameters($sQuery, $iSessionMessageDayLimit);
+
+ $oRow = mysql_fetch_object($hResult);
+ $iMessages = $oRow->cnt;
+
+ $sMsg = "Found ".$iMessages." that have been orphaned in the sessionMessages table for longer than ".$iSessionMessageDayLimit." days\r\n";
+ $sMsg.= " Purging these messages.\r\n";
+
+ $sSubject = "Messages orphaned in sessionMessages\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 sessionMessages where TO_DAYS(NOW()) - TO_DAYS(time) > ?";
+ $hResult = query_parameters($sQuery, $iSessionMessageDayLimit);
+}
ChangeSet ID: 26196
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner(a)winehq.org 2006/07/05 23:21:04
Modified files:
. : account.php
include : user.php
Log message:
Chris Morgan <cmorgan(a)alum.wpi.edu>
Use $GLOBALS['session']->destroy() instead of setting $_SESSION['current'] = "". Using "" means that $_SESSION['current']
could be set but be a string. Don't call addmsg() after logging out otherwise the session message will be lost and can
show up for other users or be stuck in the database
Patch: http://cvs.winehq.org/patch.py?id=26196
Old revision New revision Changes Path
1.24 1.25 +0 -4 appdb/account.php
1.73 1.74 +5 -4 appdb/include/user.php
Index: appdb/account.php
diff -u -p appdb/account.php:1.24 appdb/account.php:1.25
--- appdb/account.php:1.24 6 Jul 2006 4:21: 4 -0000
+++ appdb/account.php 6 Jul 2006 4:21: 4 -0000
@@ -58,10 +58,6 @@ function do_account($sCmd = null)
if($_SESSION['current'])
$_SESSION['current']->logout();
- /* destroy all session variables */
- $GLOBALS['session']->destroy();
-
- addmsg("You are successfully logged out.", "green");
redirect(apidb_fullurl("index.php"));
exit;
}
Index: appdb/include/user.php
diff -u -p appdb/include/user.php:1.73 appdb/include/user.php:1.74
--- appdb/include/user.php:1.73 6 Jul 2006 4:21: 4 -0000
+++ appdb/include/user.php 6 Jul 2006 4:21: 4 -0000
@@ -82,15 +82,16 @@ class User {
return SUCCESS;
}
- /* null out the session variable for the current user since we failed to login */
- $_SESSION['current'] = "";
+ /* destroy all session variables since we failed to login */
+ $GLOBALS['session']->destroy();
+
return USER_LOGIN_FAILED;
}
function logout()
{
- /* null out the session current variable to log us out */
- $_SESSION['current'] = "";
+ /* destroy all session variables since we are logging out */
+ $GLOBALS['session']->destroy();
}
ChangeSet ID: 26194
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner(a)winehq.org 2006/07/05 22:37:50
Modified files:
. : account.php
include : user.php
Log message:
Chris Morgan <cmorgan(a)alum.wpi.edu>
Move $_SESSION['current'] manipulation into user class. Add user::logout() to keep user::login() and logout() symmetrical
Patch: http://cvs.winehq.org/patch.py?id=26194
Old revision New revision Changes Path
1.22 1.23 +7 -4 appdb/account.php
1.72 1.73 +13 -0 appdb/include/user.php
Index: appdb/account.php
diff -u -p appdb/account.php:1.22 appdb/account.php:1.23
--- appdb/account.php:1.22 6 Jul 2006 3:37:50 -0000
+++ appdb/account.php 6 Jul 2006 3:37:50 -0000
@@ -54,7 +54,13 @@ function do_account($cmd = null)
exit;
case "logout":
+ /* if we are logged in, log us out */
+ if($_SESSION['current'])
+ $_SESSION['current']->logout();
+
+ /* destroy all session variables */
$GLOBALS['session']->destroy();
+
addmsg("You are successfully logged out.", "green");
redirect(apidb_fullurl("index.php"));
exit;
@@ -116,8 +122,7 @@ function cmd_do_new()
if($result == SUCCESS)
{
/* if we can log the user in, log them in automatically */
- if($user->login($aClean['ext_email'], $aClean['ext_password']) == SUCCESS)
- $_SESSION['current'] = $user;
+ $user->login($aClean['ext_email'], $aClean['ext_password']);
addmsg("Account created! (".$aClean['ext_email'].")", "green");
redirect(apidb_fullurl());
@@ -211,13 +216,11 @@ function cmd_do_login()
if($result == SUCCESS)
{
- $_SESSION['current'] = $user;
addmsg("You are successfully logged in as '$user->sRealname'.", "green");
redirect(apidb_fullurl("index.php"));
} else
{
retry("login","Login failed ".$note);
- $_SESSION['current'] = "";
}
}
Index: appdb/include/user.php
diff -u -p appdb/include/user.php:1.72 appdb/include/user.php:1.73
--- appdb/include/user.php:1.72 6 Jul 2006 3:37:50 -0000
+++ appdb/include/user.php 6 Jul 2006 3:37:50 -0000
@@ -75,11 +75,24 @@ class User {
// Update timestamp and clear the inactivity flag if it was set
query_parameters("UPDATE user_list SET stamp = ?, inactivity_warned = '?' WHERE userid='?'",
"NOW()", "false", $this->iUserId);
+
+ /* set the session variable for the current user to this user object */
+ $_SESSION['current'] = $this;
+
return SUCCESS;
}
+
+ /* null out the session variable for the current user since we failed to login */
+ $_SESSION['current'] = "";
return USER_LOGIN_FAILED;
}
+ function logout()
+ {
+ /* null out the session current variable to log us out */
+ $_SESSION['current'] = "";
+ }
+
/*
* Creates a new user.