From 6ab1553b5eaea743c4b828f09c7a1d37107d705c Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 01 Sep 2015 08:27:51 -0400
Subject: [PATCH] Fix so gc.sh script removes also expired sessions from sql database (#1490512)

---
 CHANGELOG |    1 +
 bin/gc.sh |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 607224d..b1dc6c6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@
 - Fix so plain text signature field uses monospace font (#1490435)
 - Fix draft removal after a message is sent and storing sent message is disabled (#1490467)
 - Fix handling of plus character in mailto: links (#1490510)
+- Fix so gc.sh script removes also expired sessions from sql database (#1490512)
 
 RELEASE 1.0.6
 -------------
diff --git a/bin/gc.sh b/bin/gc.sh
index 1ee6107..c546c81 100755
--- a/bin/gc.sh
+++ b/bin/gc.sh
@@ -24,4 +24,16 @@
 require INSTALL_PATH.'program/include/clisetup.php';
 
 $rcmail = rcube::get_instance();
+
+$session_driver   = $rcmail->config->get('session_storage', 'db');
+$session_lifetime = $rcmail->config->get('session_lifetime', 0) * 60 * 2;
+
+// Clean expired SQL sessions
+if ($session_driver == 'db' && $session_lifetime) {
+    $db = $rcmail->get_dbh();
+    $db->query("DELETE FROM " . $db->table_name('session')
+        . " WHERE changed < " . $db->now(-$session_lifetime));
+}
+
+// Clean caches and temp directory
 $rcmail->gc();

--
Gitblit v1.9.1