* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-require('./connect.db.inc.php');
+require './connect.db.inc.php';
/**
* Discards from the logger database session details for users.
* no matter what.
*/
function discardExpiredSessions($userPerms, $retentionPeriod, $minimalBacklog) {
+ switch ($userPerms) {
+ case 'user':
+ $state = 'active';
+ $isAdmin = 0;
+ break;
+ case 'admin':
+ $state = 'active';
+ $isAdmin = 1;
+ break;
+ case 'disabled':
+ $state = 'disabled';
+ $isAdmin = 0;
+ break;
+ default:
+ return;
+ }
+
XDB::execute(
"DELETE s
FROM log_sessions AS s
- JOIN (SELECT u.user_id,
+ JOIN (SELECT a.uid,
(SELECT us.start
FROM log_sessions AS us
- WHERE us.uid = u.user_id
+ WHERE us.uid = a.uid
ORDER BY us.start DESC
LIMIT {?}, 1) AS no_discard_limit
- FROM #x4dat#.auth_user_md5 AS u
- WHERE u.perms = {?}
- ORDER BY u.user_id ASC) AS ut ON (ut.user_id = s.uid)
+ FROM #x5dat#.accounts AS a
+ WHERE a.state = {?} AND a.is_admin = {?}
+ ORDER BY a.uid ASC) AS ut ON (ut.uid = s.uid)
WHERE s.start < DATE_SUB(NOW(), INTERVAL {?} MONTH)
AND s.start < ut.no_discard_limit",
- $minimalBacklog - 1, $userPerms, $retentionPeriod);
+ $minimalBacklog - 1, $state, $isAdmin, $retentionPeriod);
$affectedRows = XDB::affectedRows();
echo "Users with permission '$userPerms': removed $affectedRows sessions.\n";
function checkOrphanedSessions() {
$res = XDB::query(
"SELECT COUNT(*)
- FROM log_sessions AS s
- LEFT JOIN #x4dat#.auth_user_md5 AS u ON (u.user_id = s.uid)
- WHERE u.user_id IS NULL");
+ FROM log_sessions AS s
+ LEFT JOIN #x5dat#.accounts AS a ON (a.uid = s.uid)
+ WHERE a.uid IS NULL");
if (($count = $res->fetchOneCell())) {
echo "Orphaned sessions: found $count orphaned sessions. Please fix that.\n";
}