1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
usersessiontable.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Session\Handlers\Table
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\DB\MysqlCommonConnection
;
7
use
Bitrix\Main\DB\PgsqlConnection
;
8
use
Bitrix\Main\Type
;
9
use
Bitrix\Main\ORM\Data\DataManager
;
10
use
Bitrix\Main\ORM\Fields
;
11
28
class
UserSessionTable
extends
DataManager
29
{
31
public
const
CONNECTION_NAME
=
'user_session'
;
32
38
public
static
function
getTableName
()
39
{
40
return
'b_user_session'
;
41
}
42
50
public
static
function
getConnectionName
()
51
{
52
$pool =
Application::getInstance
()->getConnectionPool();
53
$isConnectionExists = $pool->getConnection(static::CONNECTION_NAME) !==
null
;
54
if
(!$isConnectionExists)
55
{
56
$pool->cloneConnection(
57
$pool::DEFAULT_CONNECTION_NAME,
58
static::CONNECTION_NAME
59
);
60
}
61
62
return
static::CONNECTION_NAME;
63
}
64
70
public
static
function
getMap
()
71
{
72
return
[
73
new
Fields\StringField
(
'SESSION_ID'
, [
74
'primary'
=>
true
,
75
'format'
=>
'#^[0-9a-z\-,]{6,250}$#iD'
76
]),
77
new
Fields\DatetimeField
(
'TIMESTAMP_X'
, [
78
'default_value'
=>
new
Type
\
DateTime
79
]),
80
new
Fields\TextField
(
'SESSION_DATA'
, [
81
'default_value'
=>
''
,
82
'save_data_modification'
=>
function
() {
83
return
[
84
function
(
$data
) {
85
return
base64_encode(
$data
);
86
}
87
];
88
},
89
'fetch_data_modification'
=>
function
() {
90
return
[
91
function
(
$data
) {
92
return
base64_decode(
$data
);
93
}
94
];
95
},
96
])
97
];
98
}
99
107
public
static
function
lock
($id, $timeout = 60)
108
{
109
$result
=
true
;
110
111
$pool =
Application::getInstance
()->getConnectionPool();
112
$pool->useMasterOnly(
true
);
113
114
$connection
= static::getEntity()->getConnection();
115
if
(
116
$connection
instanceof
MysqlCommonConnection
117
||
$connection
instanceof
PgsqlConnection
118
)
119
{
120
$result
=
$connection
->lock($id, (
int
)$timeout);
121
}
122
else
123
{
124
trigger_error(sprintf(
'SessionTable::lock not supported for connection of type "%s"'
, get_class(
$connection
)), E_USER_WARNING);
125
}
126
127
$pool->useMasterOnly(
false
);
128
129
return
$result
;
130
}
131
138
public
static
function
unlock
($id)
139
{
140
$pool =
Application::getInstance
()->getConnectionPool();
141
$pool->useMasterOnly(
true
);
142
143
$connection
= static::getEntity()->getConnection();
144
if
(
145
$connection
instanceof
MysqlCommonConnection
146
||
$connection
instanceof
PgsqlConnection
147
)
148
{
149
$connection
->unlock($id);
150
}
151
else
152
{
153
trigger_error(sprintf(
'SessionTable::unlock not supported for connection of type "%s"'
, get_class(
$connection
)), E_USER_WARNING);
154
}
155
156
$pool->useMasterOnly(
false
);
157
158
return
true
;
159
}
160
167
public
static
function
deleteOlderThan
($sec)
168
{
169
$pool =
Application::getInstance
()->getConnectionPool();
170
$pool->useMasterOnly(
true
);
171
172
$tableName = static::getTableName();
173
$connection
= static::getEntity()->getConnection();
174
$connection
->queryExecute(
175
sprintf(
"delete from {$tableName} where TIMESTAMP_X < %s"
,
176
$connection
->getSqlHelper()->addSecondsToDateTime(
'-'
.$sec))
177
);
178
$pool->useMasterOnly(
false
);
179
}
180
}
$connection
$connection
Определения
actionsdefinitions.php:38
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\DB\MysqlCommonConnection
Определения
mysqlcommonconnection.php:10
Bitrix\Main\DB\PgsqlConnection
Определения
pgsqlconnection.php:15
Bitrix\Main\ORM\Data\DataManager
Определения
datamanager.php:35
Bitrix\Main\ORM\Fields\DatetimeField
Определения
datetimefield.php:22
Bitrix\Main\ORM\Fields\StringField
Определения
stringfield.php:20
Bitrix\Main\ORM\Fields\TextField
Определения
textfield.php:20
Bitrix\Main\Session\Handlers\Table\UserSessionTable
Определения
usersessiontable.php:29
Bitrix\Main\Session\Handlers\Table\UserSessionTable\lock
static lock($id, $timeout=60)
Определения
usersessiontable.php:107
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getMap
static getMap()
Определения
usersessiontable.php:70
Bitrix\Main\Session\Handlers\Table\UserSessionTable\CONNECTION_NAME
const CONNECTION_NAME
Определения
usersessiontable.php:31
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getConnectionName
static getConnectionName()
Определения
usersessiontable.php:50
Bitrix\Main\Session\Handlers\Table\UserSessionTable\deleteOlderThan
static deleteOlderThan($sec)
Определения
usersessiontable.php:167
Bitrix\Main\Session\Handlers\Table\UserSessionTable\unlock
static unlock($id)
Определения
usersessiontable.php:138
Bitrix\Main\Session\Handlers\Table\UserSessionTable\getTableName
static getTableName()
Определения
usersessiontable.php:38
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
$result
$result
Определения
get_property_values.php:14
Bitrix\Main\ORM\Fields
Определения
arrayfield.php:9
Bitrix\Main\Session\Handlers\Table
Определения
usersessiontable.php:3
Bitrix\Main\Type
Определения
collection.php:2
bitrix
modules
main
lib
session
handlers
table
usersessiontable.php
Создано системой
1.14.0