/** * Delete all expired sessions from persistent storage. * * @param int $expiration * @return void */ public function sweep($expiration) { $expiration = Request::time() - Config::get('o_timeout_online'); // Fetch all sessions that are older than o_timeout_online $result = $this->table()->where('user_id', '!=', 1)->where('last_visit', '<', $expiration)->get(); $delete_ids = array(); foreach ($result as $cur_session) { $delete_ids[] = $cur_session->id; $result = $this->connection->table('users')->where_id($cur_session->user_id)->update(array('last_visit' => $cur_session->last_visit)); } // Make sure logged-in users have no more than ten sessions alive if (Auth::check()) { $uid = User::current()->id; $session_ids = $this->table()->where_user_id($uid)->order_by('last_visit', 'desc')->lists('id'); $prune_ids = array_slice($session_ids, 10); $delete_ids = array_merge($delete_ids, $prune_ids); } if (!empty($delete_ids)) { $this->table()->where_in('id', $delete_ids)->or_where('last_visit', '<', $expiration)->delete(); } }