torrentpier/library/includes/cron/jobs/sessions_cleanup.php
Roman Kelesidis fad09cf0eb
Updated copyright year (#1201)
* Updated copyright year

* Updated
2023-12-12 22:14:01 +07:00

55 lines
1.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
$user_session_expire_time = TIMENOW - (int)$bb_cfg['user_session_duration'];
$admin_session_expire_time = TIMENOW - (int)$bb_cfg['admin_session_duration'];
$user_session_gc_time = $user_session_expire_time - (int)$bb_cfg['user_session_gc_ttl'];
$admin_session_gc_time = $admin_session_expire_time;
// ############################ Tables LOCKED ################################
DB()->lock([
BB_USERS . ' u',
BB_SESSIONS . ' s'
]);
// Update user's session time
DB()->query("
UPDATE
" . BB_USERS . " u,
" . BB_SESSIONS . " s
SET
u.user_session_time = IF(u.user_session_time < s.session_time, s.session_time, u.user_session_time)
WHERE
u.user_id = s.session_user_id
AND s.session_user_id != " . GUEST_UID . "
AND (
(s.session_time < $user_session_expire_time AND s.session_admin = 0)
OR
(s.session_time < $admin_session_expire_time AND s.session_admin != 0)
)
");
DB()->unlock();
// ############################ Tables UNLOCKED ##############################
// Delete staled sessions
DB()->query("
DELETE s
FROM " . BB_SESSIONS . " s
WHERE
(s.session_time < $user_session_gc_time AND s.session_admin = 0)
OR
(s.session_time < $admin_session_gc_time AND s.session_admin != 0)
");