From b096e907cf003659cf1b504787363352191fc639 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 13 Feb 2018 15:06:51 -0800 Subject: Run SessionHandler::write() into a transaction --- app/Core/Session/SessionHandler.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'app/Core') diff --git a/app/Core/Session/SessionHandler.php b/app/Core/Session/SessionHandler.php index 135e0ab0..df32a74e 100644 --- a/app/Core/Session/SessionHandler.php +++ b/app/Core/Session/SessionHandler.php @@ -54,17 +54,23 @@ class SessionHandler implements SessionHandlerInterface { $lifetime = time() + (ini_get('session.gc_maxlifetime') ?: 1440); + $this->db->startTransaction(); + if ($this->db->table(self::TABLE)->eq('id', $sessionID)->exists()) { - return $this->db->table(self::TABLE)->eq('id', $sessionID)->update(array( + $this->db->table(self::TABLE)->eq('id', $sessionID)->update([ + 'expire_at' => $lifetime, + 'data' => $data, + ]); + } else { + $this->db->table(self::TABLE)->insert([ + 'id' => $sessionID, 'expire_at' => $lifetime, 'data' => $data, - )); + ]); } - return $this->db->table(self::TABLE)->insert(array( - 'id' => $sessionID, - 'expire_at' => $lifetime, - 'data' => $data, - )); + $this->db->closeTransaction(); + + return true; } } -- cgit v1.2.3