Index: kernel/session/session.php =================================================================== --- kernel/session/session.php (revision 13152) +++ kernel/session/session.php (working copy) @@ -298,32 +298,38 @@ function GetExpiredSIDs() { - $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.$this->TimestampField.' > '.adodb_mktime(); - return $this->Conn->GetCol($query); + $sql = 'SELECT ' . $this->IDField . ' + FROM ' . $this->TableName . ' + WHERE ' . $this->TimestampField . ' > ' . adodb_mktime(); + + return $this->Conn->GetCol($sql); } function DeleteExpired() { $expired_sids = $this->GetExpiredSIDs(); + if ($expired_sids) { $sessionlog_table = $this->Application->getUnitOption('session-log', 'TableName'); - $session_log_sql = - ' UPDATE '.$sessionlog_table.' - SET Status = 2, SessionEnd = - ( SELECT '.$this->TimestampField.' - '.$this->SessionTimeout.' - FROM '.$this->TableName.' - WHERE '.$this->IDField.' = '.$sessionlog_table.'.SessionId - ) - WHERE Status = 0 AND SessionId IN ('.join(',', $expired_sids).')'; + if ($sessionlog_table) { + $sub_select = ' SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . ' + FROM ' . $this->TableName . ' + WHERE ' . $this->IDField . ' = ' . $sessionlog_table . '.SessionId'; + + $session_log_sql = + ' UPDATE ' . $sessionlog_table . ' + SET Status = ' . SESSION_LOG_EXPIRED . ', SessionEnd = (' . $sub_select . ') + WHERE Status = ' . SESSION_LOG_ACTIVE . ' AND SessionId IN (' . implode(',', $expired_sids) . ')'; $this->Conn->Query($session_log_sql); } - $where_clause = ' WHERE '.$this->IDField.' IN ("'.implode('","',$expired_sids).'")'; - $sql = 'DELETE FROM '.$this->SessionDataTable.$where_clause; + $where_clause = ' WHERE ' . $this->IDField . ' IN ("' . implode('","', $expired_sids) . '")'; + + $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause; $this->Conn->Query($sql); - $sql = 'DELETE FROM '.$this->TableName.$where_clause; + $sql = 'DELETE FROM ' . $this->TableName . $where_clause; $this->Conn->Query($sql); // delete debugger ouputs left of expired sessions @@ -334,6 +340,7 @@ } } } + return $expired_sids; } @@ -601,7 +608,7 @@ return ; } - $this->DeleteExpired(); +// $this->DeleteExpired(); // called from u:OnDeleteExpiredSessions agent now if ($this->expired || ($this->CachedSID && !$this->_fromGet && !$this->SessionSet)) { $this->RemoveSessionCookie(); Index: units/users/users_config.php =================================================================== --- units/users/users_config.php (revision 13159) +++ units/users/users_config.php (working copy) @@ -103,9 +103,10 @@ 5 => 'mode', ), - 'RegularEvents' => Array( - 'membership_expiration' => Array('EventName' => 'OnCheckExpiredMembership', 'RunInterval' => 1800, 'Type' => reAFTER), - ), + 'RegularEvents' => Array( + 'membership_expiration' => Array('EventName' => 'OnCheckExpiredMembership', 'RunInterval' => 1800, 'Type' => reAFTER), + 'delete_expired_sessions' => Array('EventName' => 'OnDeleteExpiredSessions', 'RunInterval' => 86400, 'Type' => reAFTER), + ), 'IDField' => 'PortalUserId', Index: units/users/users_event_handler.php =================================================================== --- units/users/users_event_handler.php (revision 13168) +++ units/users/users_event_handler.php (working copy) @@ -188,6 +188,20 @@ } /** + * [AGENT] Deletes expired sessions + * + * @param kEvent $event + */ + function OnDeleteExpiredSessions(&$event) + { + if (defined('IS_INSTALL') && IS_INSTALL) { + return ; + } + + $this->Application->Session->DeleteExpired(); + } + + /** * Checks user data and logs it in if allowed * * OnLogin is called from u:autoLoginUser and password is supplied