1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usersessiontable.php
См. документацию.
1<?php
2
4
11
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 (
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 (
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
Определения actionsdefinitions.php:38
static getInstance()
Определения application.php:98
$data['IS_AVAILABLE']
Определения .description.php:13
$result
Определения get_property_values.php:14
Определения collection.php:2