Index: kernel/session/session.php =================================================================== --- kernel/session/session.php (revision 13432) +++ kernel/session/session.php (working copy) @@ -309,41 +309,47 @@ { $expired_sids = $this->GetExpiredSIDs(); - if ($expired_sids) { - $sessionlog_table = $this->Application->getUnitOption('session-log', 'TableName'); + $this->DeleteSessions($expired_sids); - if ($sessionlog_table) { - $sub_select = ' SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . ' - FROM ' . $this->TableName . ' - WHERE ' . $this->IDField . ' = ' . $sessionlog_table . '.SessionId'; + return $expired_sids; + } - $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); - } + function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED) + { + if (!$session_ids) { + return ; + } - $where_clause = ' WHERE ' . $this->IDField . ' IN ("' . implode('","', $expired_sids) . '")'; + $log_table = $this->Application->getUnitOption('session-log', 'TableName'); - $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause; - $this->Conn->Query($sql); + if ($log_table) { + // mark session with proper status + $sub_sql = 'SELECT ' . $this->TimestampField . ' - ' . $this->SessionTimeout . ' + FROM ' . $this->TableName . ' + WHERE ' . $this->IDField . ' = ' . $log_table . '.SessionId'; - $sql = 'DELETE FROM ' . $this->TableName . $where_clause; - $this->Conn->Query($sql); - - // delete debugger ouputs left of expired sessions - foreach ($expired_sids as $expired_sid) { - $debug_file = WRITEABLE . '/cache/debug_@' . $expired_sid . '@.txt'; - if (file_exists($debug_file)) { - @unlink($debug_file); - } - } + $sql = 'UPDATE ' . $log_table . ' + SET Status = ' . $delete_reason . ', SessionEnd = (' . $sub_sql . ') + WHERE Status = ' . SESSION_LOG_ACTIVE . ' AND SessionId IN (' . implode(',', $session_ids) . ')'; + $this->Conn->Query($sql); } - return $expired_sids; - } + $where_clause = ' WHERE ' . $this->IDField . ' IN (' . implode(',', $session_ids) . ')'; + $sql = 'DELETE FROM ' . $this->SessionDataTable . $where_clause; + $this->Conn->Query($sql); + $sql = 'DELETE FROM ' . $this->TableName . $where_clause; + $this->Conn->Query($sql); + + // delete debugger ouputs left of deleted sessions + foreach ($session_ids as $session_id) { + $debug_file = WRITEABLE . '/cache/debug_@' . $session_id . '@.txt'; + if (file_exists($debug_file)) { + @unlink($debug_file); + } + } + } + function LoadPersistentVars(&$session) { $user_id = $session->RecallVar('user_id'); @@ -1303,6 +1309,17 @@ } /** + * Deletes given sessions + * + * @return Array + * @access private + */ + function DeleteSessions($session_ids, $delete_reason = SESSION_LOG_EXPIRED) + { + return $this->Storage->DeleteSessions($session_ids, $delete_reason); + } + + /** * Allows to check if user in this session is logged in or not * * @return bool Index: units/users/users_event_handler.php =================================================================== --- units/users/users_event_handler.php (revision 13432) +++ units/users/users_event_handler.php (working copy) @@ -1583,6 +1583,16 @@ $this->Application->EmailEventUser($email_event, $user_id); $this->Application->EmailEventAdmin($email_event); } + + // deletes sessions from users, that are no longer active + if (($prev_status != $new_status) && ($new_status != STATUS_ACTIVE)) { + $sql = 'SELECT SessionKey + FROM ' . TABLE_PREFIX . 'UserSession + WHERE PortalUserId = ' . $user_id; + $session_ids = $this->Conn->GetCol($sql); + + $this->Application->Session->DeleteSessions($session_ids); + } } /**