Skip to content

Commit ebabf40

Browse files
author
a.anokhin
committed
Fix session storage with postgres
1 parent f7bab9e commit ebabf40

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

session/src/lmbSessionDbStorage.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/*
33
* Limb PHP Framework
44
*
5-
* @link http://limb-project.com
5+
* @link http://limb-project.com
66
* @copyright Copyright © 2004-2009 BIT(http://bit-creative.com)
7-
* @license LGPL http://www.gnu.org/copyleft/lesser.html
7+
* @license LGPL http://www.gnu.org/copyleft/lesser.html
88
*/
99
lmb_require('limb/session/src/lmbSessionStorage.interface.php');
1010
lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php');
@@ -108,13 +108,15 @@ function storageWrite($session_id, $value)
108108
$data = array('last_activity_time' => time(),
109109
'session_data' => $value);
110110

111+
$this->db->begin();
111112
if($rs->count() > 0)
112113
$this->db->update('lmb_session', $data, $crit);
113114
else
114115
{
115116
$data['session_id'] = "{$session_id}";
116117
$this->db->insert('lmb_session', $data, null);
117118
}
119+
$this->db->commit();
118120
}
119121

120122
/**
@@ -124,8 +126,10 @@ function storageWrite($session_id, $value)
124126
*/
125127
function storageDestroy($session_id)
126128
{
129+
$this->db->begin();
127130
$this->db->delete('lmb_session',
128131
new lmbSQLFieldCriteria('session_id', $session_id));
132+
$this->db->commit();
129133
}
130134

131135
/**
@@ -139,8 +143,10 @@ function storageGc($max_life_time)
139143
if($this->max_life_time)
140144
$max_life_time = $this->max_life_time;
141145

146+
$this->db->begin();
142147
$this->db->delete('lmb_session',
143148
new lmbSQLFieldCriteria('last_activity_time', time() - $max_life_time, lmbSQLFieldCriteria::LESS));
149+
$this->db->commit();
144150
}
145151
}
146152

web_app/src/filter/lmbSessionStartupFilter.class.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class lmbSessionStartupFilter implements lmbInterceptingFilter
2727
* @see lmbInterceptingFilter :: run()
2828
* @uses LIMB_SESSION_USE_DB_DRIVER
2929
*/
30-
function run($filter_chain, $session_in_db = false, $session_in_db_lifetime = null)
30+
function run($filter_chain)
3131
{
32+
$session_in_db = defined('LIMB_SESSION_USE_DB_DRIVER') ? LIMB_SESSION_USE_DB_DRIVER : false;
3233
if($session_in_db)
33-
$storage = $this->_createDBSessionStorage($session_in_db_lifetime);
34+
$storage = $this->_createDBSessionStorage();
3435
else
3536
$storage = $this->_createNativeSessionStorage();
3637

@@ -50,8 +51,10 @@ protected function _createNativeSessionStorage()
5051
* Creates object of {@link lmbSessionDbStorage} class.
5152
* @see lmbInterceptingFilter :: run()
5253
*/
53-
protected function _createDBSessionStorage($lifetime)
54+
protected function _createDBSessionStorage()
5455
{
56+
$lifetime = defined('LIMB_SESSION_DB_MAX_LIFE_TIME') ? LIMB_SESSION_DB_MAX_LIFE_TIME : null;
57+
5558
lmb_require('limb/session/src/lmbSessionDbStorage.class.php');
5659
$db_connection = lmbToolkit :: instance()->getDefaultDbConnection();
5760
return new lmbSessionDbStorage($db_connection, $lifetime);

0 commit comments

Comments
 (0)