Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/architecture/db_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The other tables are optional. The example DB schema contains several other tabl

Table | Description
------|------------
sys_session | Stores session data. This table is required if you want to keep your session data in DB
lmb_session | Stores session data. This table is required if you want to keep your session data in DB
sys_tree | Stores data about tree structure (materialized path algorithm). This table contains also hierarhies and has no idea how these hierarhies are used. You can remove this table for simple projects e.g. file-based wiki or simple news project.
sys_object_to_node | Contains information how limb-object's are connected to tree nodes
sys_service | Contains list of Services. sys_service and sys_object_to_service tables are required only if some of your limb-objects will be connected to Services.
Expand Down
12 changes: 6 additions & 6 deletions session/docs/ru/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ lmbSessionDbStorage — класс, который позволяет храни

SQL-код структуры таблицы, где хранятся сессионные данные показан ниже:

CREATE TABLE `sys_session` (
`session_id` VARCHAR(50) NOT NULL DEFAULT '',
`session_data` BLOB NOT NULL,
`last_activity_time` BIGINT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
CREATE TABLE `lmb_session` (
`session_id` VARCHAR(50) NOT NULL DEFAULT '',
`session_data` BLOB NOT NULL,
`last_activity_time` BIGINT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

lmbSessionDbStorage в методе installStorage() регистрирует в качестве обработчиков сессионных сообщений свои методы, такие как sessionStart(), sessionRead(), sessionWrite() и т.д.

Expand Down
15 changes: 11 additions & 4 deletions session/src/lmbSessionDbStorage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
* @link http://limb-project.com
* @link http://limb-project.com
* @copyright Copyright © 2004-2009 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/session/src/lmbSessionStorage.interface.php');
lmb_require('limb/dbal/src/criteria/lmbSQLFieldCriteria.class.php');
Expand Down Expand Up @@ -34,10 +34,11 @@ class lmbSessionDbStorage implements lmbSessionStorage
/**
* Constructor.
* @param lmbDbConnection database connection object
* @param integer maximum session life time
*/
function __construct($db_connection, $max_life_time = null)
function __construct($db_connection)
{
$max_life_time = lmb_env_get('LIMB_SESSION_DB_MAX_LIFE_TIME');

$this->max_life_time = $max_life_time;

$this->db = new lmbSimpleDb($db_connection);
Expand Down Expand Up @@ -108,13 +109,15 @@ function storageWrite($session_id, $value)
$data = array('last_activity_time' => time(),
'session_data' => $value);

$this->db->begin();
if($rs->count() > 0)
$this->db->update('lmb_session', $data, $crit);
else
{
$data['session_id'] = "{$session_id}";
$this->db->insert('lmb_session', $data, null);
}
$this->db->commit();
}

/**
Expand All @@ -124,8 +127,10 @@ function storageWrite($session_id, $value)
*/
function storageDestroy($session_id)
{
$this->db->begin();
$this->db->delete('lmb_session',
new lmbSQLFieldCriteria('session_id', $session_id));
$this->db->commit();
}

/**
Expand All @@ -139,8 +144,10 @@ function storageGc($max_life_time)
if($this->max_life_time)
$max_life_time = $this->max_life_time;

$this->db->begin();
$this->db->delete('lmb_session',
new lmbSQLFieldCriteria('last_activity_time', time() - $max_life_time, lmbSQLFieldCriteria::LESS));
$this->db->commit();
}
}

7 changes: 4 additions & 3 deletions session/tests/cases/lmbSessionDbStorageTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/*
* Limb PHP Framework
*
* @link http://limb-project.com
* @link http://limb-project.com
* @copyright Copyright © 2004-2009 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/session/src/lmbSessionDbStorage.class.php');
lmb_require('limb/dbal/src/lmbSimpleDb.class.php');
Expand Down Expand Up @@ -183,7 +183,8 @@ function testStorageGcTrue()

function testStorageGcUseSettedMaxLifeTime()
{
$driver = new lmbSessionDbStorage($this->conn, $max_life_time = 500);
lmb_env_setor('LIMB_SESSION_DB_MAX_LIFE_TIME', 500);
$driver = new lmbSessionDbStorage($this->conn);

$this->db->insert('lmb_session',
array('session_id' => "whatever",
Expand Down
4 changes: 2 additions & 2 deletions web_app/docs/ru/web_app/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$session = lmbToolkit :: instance()->getSession();
$session->set('my_var', $value); // Поставить значение в сессию
$var = $session->get('my_var'); // Получить значение из сессии

$session->foo = $value; // Поставить значение в сессию
$bar = $session->foo; // Получить значение из сессии

Expand Down Expand Up @@ -37,7 +37,7 @@ lmbSessionStartupFilter опирается на константу **LIMB_SESSIO

Для хранения сессионных данных в базе данных используется таблице **sys_session** со следующей структурой:

CREATE TABLE `sys_session` (
CREATE TABLE `lmb_session` (
`session_id` VARCHAR(50) NOT NULL DEFAULT '',
`session_data` BLOB NOT NULL,
`last_activity_time` BIGINT(11) UNSIGNED DEFAULT NULL,
Expand Down
10 changes: 6 additions & 4 deletions web_app/src/filter/lmbSessionStartupFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class lmbSessionStartupFilter implements lmbInterceptingFilter
* @see lmbInterceptingFilter :: run()
* @uses LIMB_SESSION_USE_DB_DRIVER
*/
function run($filter_chain, $session_in_db = false, $session_in_db_lifetime = null)
function run($filter_chain)
{
$session_in_db = lmb_env_get('LIMB_SESSION_USE_DB_DRIVER', false);

if($session_in_db)
$storage = $this->_createDBSessionStorage($session_in_db_lifetime);
$storage = $this->_createDBSessionStorage();
else
$storage = $this->_createNativeSessionStorage();

Expand All @@ -50,11 +52,11 @@ protected function _createNativeSessionStorage()
* Creates object of {@link lmbSessionDbStorage} class.
* @see lmbInterceptingFilter :: run()
*/
protected function _createDBSessionStorage($lifetime)
protected function _createDBSessionStorage()
{
lmb_require('limb/session/src/lmbSessionDbStorage.class.php');
$db_connection = lmbToolkit :: instance()->getDefaultDbConnection();
return new lmbSessionDbStorage($db_connection, $lifetime);
return new lmbSessionDbStorage($db_connection);
}
}