From 2365afb99004deb40f5641a3d0a497eb78bd1a20 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 29 Mar 2016 04:32:11 +0000
Subject: [PATCH] Session: Create SessionData object on demand

Session backend issues update via write on new session which caused
assertion to fail.
---
 include/class.ostsession.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/class.ostsession.php b/include/class.ostsession.php
index 8581965eb..dbb5cf631 100644
--- a/include/class.ostsession.php
+++ b/include/class.ostsession.php
@@ -174,6 +174,8 @@ extends VerySimpleModel {
 
 class DbSessionBackend
 extends SessionBackend {
+    var $data = null;
+
     function read($id) {
         try {
             $this->data = SessionData::objects()->filter([
@@ -200,7 +202,9 @@ extends SessionBackend {
         $ttl = $this && method_exists($this, 'getTTL')
             ? $this->getTTL() : SESSION_TTL;
 
-        assert($this->data->session_id == $id);
+        // Create a session data obj if not loaded.
+        if (!isset($this->data))
+            $this->data = new SessionData(['session_id' => $id]);
 
         $this->data->session_data = $data;
         $this->data->session_expire =
-- 
GitLab