DB may have been closed before write() - reconnect if it's not active
authorChuck Hagenbuch <chuck@horde.org>
Mon, 24 Jan 2011 03:59:04 +0000 (22:59 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 24 Jan 2011 03:59:04 +0000 (22:59 -0500)
framework/SessionHandler/lib/Horde/SessionHandler/Storage/Sql.php

index 39cda3c..281cb33 100644 (file)
@@ -72,11 +72,14 @@ class Horde_SessionHandler_Storage_Sql extends Horde_SessionHandler_Storage
     public function close()
     {
         /* Close any open transactions. */
-        try {
-            $this->_db->commitDbTransaction();
-        } catch (Horde_Db_Exception $e) {
-            throw new Horde_SessionHandler_Exception($e);
+        if ($this->_db->transactionStarted()) {
+            try {
+                $this->_db->commitDbTransaction();
+            } catch (Horde_Db_Exception $e) {
+                return false;
+            }
         }
+        return true;
     }
 
     /**
@@ -104,6 +107,8 @@ class Horde_SessionHandler_Storage_Sql extends Horde_SessionHandler_Storage
      */
     public function write($id, $session_data)
     {
+        if (!$this->_db->isActive()) { $this->_db->reconnect(); }
+
         /* Build the SQL query. */
         $query = sprintf('SELECT session_id FROM %s WHERE session_id = ?',
                          $this->_params['table']);