Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
eventtable.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Internals\EventService
;
4
5
use
Bitrix\Main\ORM\Data\DataManager
;
6
use
Bitrix\Main\ORM\Query\Query
;
7
use
Bitrix\Main\Type\DateTime
;
8
25
class
EventTable
extends
DataManager
26
{
27
private
const
LOST_LIMIT = 50;
28
private
const
LOST_TTL = 60;
29
30
public
static
function
getTableName
(): string
31
{
32
return
'b_sonet_scorer_event'
;
33
}
34
35
public
static
function
getClass
(): string
36
{
37
return
static::class;
38
}
39
40
public
static
function
getMap
(): array
41
{
42
return
[
43
'ID'
=> [
44
'data_type'
=>
'integer'
,
45
'primary'
=>
true
,
46
'autocomplete'
=>
true
,
47
],
48
'HID'
=> [
49
'data_type'
=>
'string'
,
50
'required'
=>
true
,
51
],
52
'TYPE'
=> [
53
'data_type'
=>
'string'
,
54
'required'
=>
true
,
55
],
56
'DATA'
=> [
57
'data_type'
=>
'text'
,
58
'required'
=>
true
,
59
],
60
'LOG_DATA'
=> [
61
'data_type'
=>
'text'
,
62
],
63
'CREATED'
=> [
64
'data_type'
=>
'datetime'
65
],
66
'PROCESSED'
=> [
67
'data_type'
=>
'datetime'
68
],
69
];
70
}
71
79
public
static
function
markProcessed
(array $filter)
80
{
81
$entity
= static::getEntity();
82
$connection =
$entity
->getConnection();
83
84
\CTimeZone::disable();
85
$res = $connection->query(sprintf(
86
'UPDATE %s SET PROCESSED = CURRENT_TIMESTAMP WHERE %s'
,
87
$connection->getSqlHelper()->quote(
$entity
->getDbTableName()),
88
Query::buildFilterSql(
$entity
, $filter)
89
));
90
\CTimeZone::enable();
91
92
return
$res;
93
}
94
101
public
static
function
hasLostEvents
(): bool
102
{
103
$res =
self::getList
([
104
'filter'
=> [
105
'<PROCESSED'
=>
DateTime::createFromTimestamp
(0),
106
],
107
'limit'
=> 1
108
]);
109
110
if
($res->getSelectedRowsCount() > 0)
111
{
112
return
true
;
113
}
114
115
return
false
;
116
}
117
125
public
static
function
getLostEvents
(): array
126
{
127
$limit = \COption::GetOptionString(
'socialnetwork'
,
"sonetLostCountersLimit"
, 0);
128
if
(!$limit)
129
{
130
$limit = self::LOST_LIMIT;
131
}
132
133
\CTimeZone::disable();
134
$res =
self::getList
([
135
'filter'
=> [
136
'<PROCESSED'
=>
DateTime::createFromTimestamp
(0),
137
'<CREATED'
=>
DateTime::createFromTimestamp
(time() - self::LOST_TTL)
138
],
139
'limit'
=> $limit
140
]);
141
\CTimeZone::enable();
142
143
$events = [];
144
while
($row = $res->fetch())
145
{
146
$events[] = $row;
147
}
148
149
return
$events;
150
}
151
159
public
static
function
deleteList
(array $filter)
160
{
161
$entity
= static::getEntity();
162
$connection =
$entity
->getConnection();
163
164
$enabled = \CTimeZone::Enabled();
165
if
($enabled)
166
{
167
\CTimeZone::Disable();
168
}
169
170
$sql = sprintf(
171
'DELETE FROM %s WHERE %s'
,
172
$connection->getSqlHelper()->quote(
$entity
->getDbTableName()),
173
Query::buildFilterSql(
$entity
, $filter)
174
);
175
$res = $connection->query($sql);
176
177
if
($enabled)
178
{
179
\CTimeZone::Enable();
180
}
181
182
return
$res;
183
}
184
}
Bitrix\Main\ORM\Data\DataManager
Definition
datamanager.php:33
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\Main\ORM\Data\DataManager\$entity
static $entity
Definition
datamanager.php:45
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\Type\DateTime\createFromTimestamp
static createFromTimestamp($timestamp)
Definition
datetime.php:246
Bitrix\Socialnetwork\Internals\EventService\EventTable
Definition
eventtable.php:26
Bitrix\Socialnetwork\Internals\EventService\EventTable\getMap
static getMap()
Definition
eventtable.php:40
Bitrix\Socialnetwork\Internals\EventService\EventTable\deleteList
static deleteList(array $filter)
Definition
eventtable.php:159
Bitrix\Socialnetwork\Internals\EventService\EventTable\getLostEvents
static getLostEvents()
Definition
eventtable.php:125
Bitrix\Socialnetwork\Internals\EventService\EventTable\markProcessed
static markProcessed(array $filter)
Definition
eventtable.php:79
Bitrix\Socialnetwork\Internals\EventService\EventTable\getClass
static getClass()
Definition
eventtable.php:35
Bitrix\Socialnetwork\Internals\EventService\EventTable\hasLostEvents
static hasLostEvents()
Definition
eventtable.php:101
Bitrix\Socialnetwork\Internals\EventService\EventTable\getTableName
static getTableName()
Definition
eventtable.php:30
Bitrix\Socialnetwork\Internals\EventService
Definition
cleanagent.php:3
modules
socialnetwork
lib
internals
eventservice
eventtable.php
Создано системой
1.10.0