Skip to content
Snippets Groups Projects
Commit 5a8fdeae authored by JediKev's avatar JediKev
Browse files

cron: Delete Expired Sessions

This addresses an issue where expired sessions would not be removed from
the database. This caused the session table to fill up and create
unnecessary issues. This adds a cleanup method to remove all expired
sessions from the database.
parent d2ef3b1f
Branches
Tags
No related merge requests found
...@@ -51,6 +51,11 @@ class Cron { ...@@ -51,6 +51,11 @@ class Cron {
AttachmentFile::deleteOrphans(); AttachmentFile::deleteOrphans();
} }
function CleanExpiredSessions() {
require_once(INCLUDE_DIR.'class.ostsession.php');
DbSessionBackend::cleanup();
}
function MaybeOptimizeTables() { function MaybeOptimizeTables() {
// Once a week on a 5-minute cron // Once a week on a 5-minute cron
$chance = rand(1,2000); $chance = rand(1,2000);
...@@ -100,6 +105,7 @@ class Cron { ...@@ -100,6 +105,7 @@ class Cron {
self::MailFetcher(); self::MailFetcher();
self::TicketMonitor(); self::TicketMonitor();
self::PurgeLogs(); self::PurgeLogs();
self::CleanExpiredSessions();
// Run file purging about every 10 cron runs // Run file purging about every 10 cron runs
if (mt_rand(1, 9) == 4) if (mt_rand(1, 9) == 4)
self::CleanOrphanedFiles(); self::CleanOrphanedFiles();
......
...@@ -158,6 +158,10 @@ abstract class SessionBackend { ...@@ -158,6 +158,10 @@ abstract class SessionBackend {
return $this->update($id, $i['touched'] ? session_encode() : $data); return $this->update($id, $i['touched'] ? session_encode() : $data);
} }
function cleanup() {
$this->gc(0);
}
abstract function read($id); abstract function read($id);
abstract function update($id, $data); abstract function update($id, $data);
abstract function destroy($id); abstract function destroy($id);
...@@ -220,6 +224,10 @@ extends SessionBackend { ...@@ -220,6 +224,10 @@ extends SessionBackend {
return SessionData::objects()->filter(['session_id' => $id])->delete(); return SessionData::objects()->filter(['session_id' => $id])->delete();
} }
function cleanup() {
self::gc(0);
}
function gc($maxlife){ function gc($maxlife){
SessionData::objects()->filter([ SessionData::objects()->filter([
'session_expire__lte' => SqlFunction::NOW() 'session_expire__lte' => SqlFunction::NOW()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment