Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
usersessiontable.php
1
<?php
2
namespace
Bitrix\Main\Session\Handlers\Table
;
3
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\DB\MysqlCommonConnection
;
7
use
Bitrix\Main\Entity
;
8
use
Bitrix\Main\Type
;
9
26
class
UserSessionTable
extends
Entity\DataManager
27
{
29
public
const
CONNECTION_NAME
=
'user_session'
;
30
36
public
static
function
getTableName
()
37
{
38
return
'b_user_session'
;
39
}
40
48
public
static
function
getConnectionName
()
49
{
50
$pool =
Application::getInstance
()->getConnectionPool();
51
$isConnectionExists = $pool->getConnection(static::CONNECTION_NAME) !==
null
;
52
if
(!$isConnectionExists)
53
{
54
$pool->cloneConnection(
55
$pool::DEFAULT_CONNECTION_NAME,
56
static::CONNECTION_NAME
57
);
58
}
59
60
return
static::CONNECTION_NAME;
61
}
62
68
public
static
function
getMap
()
69
{
70
return
[
71
new
Entity\StringField(
'SESSION_ID'
, [
72
'primary'
=>
true
,
73
'format'
=>
'#^[0-9a-z\-,]{6,250}$#iD'
74
]),
75
new
Entity\DatetimeField(
'TIMESTAMP_X'
, [
76
'default_value'
=>
new
Type
\
DateTime
77
]),
78
new
Entity\TextField(
'SESSION_DATA'
, [
79
'default_value'
=>
''
,
80
'save_data_modification'
=>
function
() {
81
return
[
82
function
($data) {
83
return
base64_encode($data);
84
}
85
];
86
},
87
'fetch_data_modification'
=>
function
() {
88
return
[
89
function
($data) {
90
return
base64_decode($data);
91
}
92
];
93
},
94
])
95
];
96
}
97
105
public
static
function
lock
($id, $timeout = 60)
106
{
107
$result =
true
;
108
109
$pool =
Application::getInstance
()->getConnectionPool();
110
$pool->useMasterOnly(
true
);
111
112
$connection = static::getEntity()->getConnection();
113
if
($connection instanceof
MysqlCommonConnection
)
114
{
115
$result = $connection->lock($id, (
int
)$timeout);
116
}
117
else
118
{
119
trigger_error(sprintf(
'SessionTable::lock not supported for connection of type "%s"'
, get_class($connection)), E_USER_WARNING);
120
}
121
122
$pool->useMasterOnly(
false
);
123
124
return
$result;
125
}
126
133
public
static
function
unlock
($id)
134
{
135
$pool =
Application::getInstance
()->getConnectionPool();
136
$pool->useMasterOnly(
true
);
137
138
$connection = static::getEntity()->getConnection();
139
if
($connection instanceof
MysqlCommonConnection
)
140
{
141
$connection->unlock($id);
142
}
143
else
144
{
145
trigger_error(sprintf(
'SessionTable::unlock not supported for connection of type "%s"'
, get_class($connection)), E_USER_WARNING);
146
}
147
148
$pool->useMasterOnly(
false
);
149
150
return
true
;
151
}
152
159
public
static
function
deleteOlderThan
($sec)
160
{
161
$pool =
Application::getInstance
()->getConnectionPool();
162
$pool->useMasterOnly(
true
);
163
164
$tableName = static::getTableName();
165
$connection = static::getEntity()->getConnection();
166
$connection->queryExecute(
167
sprintf(
"delete from {$tableName} where TIMESTAMP_X < %s"
,
168
$connection->getSqlHelper()->addSecondsToDateTime(
'-'
.$sec))
169
);
170
$pool->useMasterOnly(
false
);
171
}
172
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getInstance
static getInstance()
Definition
application.php:95
Bitrix\Main\DB\MysqlCommonConnection
Definition
mysqlcommonconnection.php:9
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\Session\Handlers\Table\UserSessionTable
Definition
usersessiontable.php:27
Bitrix\Main\Session\Handlers\Table\UserSessionTable\lock
static lock($id, $timeout=60)
Definition
usersessiontable.php:105
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getMap
static getMap()
Definition
usersessiontable.php:68
Bitrix\Main\Session\Handlers\Table\UserSessionTable\CONNECTION_NAME
const CONNECTION_NAME
Definition
usersessiontable.php:29
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getConnectionName
static getConnectionName()
Definition
usersessiontable.php:48
Bitrix\Main\Session\Handlers\Table\UserSessionTable\deleteOlderThan
static deleteOlderThan($sec)
Definition
usersessiontable.php:159
Bitrix\Main\Session\Handlers\Table\UserSessionTable\unlock
static unlock($id)
Definition
usersessiontable.php:133
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getTableName
static getTableName()
Definition
usersessiontable.php:36
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\Session\Handlers\Table
Definition
usersessiontable.php:2
Bitrix\Main\Type
Definition
collection.php:2
modules
main
lib
session
handlers
table
usersessiontable.php
Создано системой
1.10.0