Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventtable.php
1<?php
2
4
8
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}
static getList(array $parameters=array())
static createFromTimestamp($timestamp)
Definition datetime.php:246