From: Stéphane Jacob Date: Sun, 28 Feb 2010 02:04:18 +0000 (+0100) Subject: Fixes calls to auth_user_* from compliance cron. X-Git-Tag: xorg/1.0.0~332^2~148 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=7be5c7d5294b96fdc335d4816b8fb23dd2824d92;p=platal.git Fixes calls to auth_user_* from compliance cron. Signed-off-by: Stéphane Jacob --- diff --git a/bin/cron/compliance.php b/bin/cron/compliance.php index 23739ff..ee23dad 100755 --- a/bin/cron/compliance.php +++ b/bin/cron/compliance.php @@ -20,7 +20,7 @@ * 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. @@ -31,21 +31,38 @@ require('./connect.db.inc.php'); * 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"; @@ -57,9 +74,9 @@ function discardExpiredSessions($userPerms, $retentionPeriod, $minimalBacklog) { 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"; }