1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
queue.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\LiveFeed\Counter\Queue;
4
5use Bitrix\Main\Application;
6use Bitrix\Socialnetwork\Internals\LiveFeed\Counter\Exception\CounterQueuePopException;
7
8class Queue
9{
10 private array $popped = [];
11 private static Queue|null $instance = null;
12 private static array $inQueue = [];
13
14 public static function isInQueue(int $userId): bool
15 {
16 if (!array_key_exists($userId, self::$inQueue))
17 {
19 'filter' => [
20 '=USER_ID' => $userId
21 ]
22 ]);
23
24 self::$inQueue[$userId] = (bool) $res;
25 }
26
27 return self::$inQueue[$userId];
28 }
29
30 public static function getInstance()
31 {
32 if (!self::$instance)
33 {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
42 private function __construct()
43 {
44
45 }
46
47 public function add(int $userId, string $type, array $logs): void
48 {
49 if (empty($logs))
50 {
51 return;
52 }
53
54 $connection = Application::getConnection();
55 $helper = $connection->getSqlHelper();
56
57 $req = [];
58 foreach ($logs as $logId)
59 {
60 $req[] = $userId .',\''. $helper->forSql($type) . '\',' . (int)$logId;
61 }
62
63 $sql = "
64 INSERT INTO " . $helper->quote(QueueTable::getTableName()) . "
65 (" . $helper->quote('USER_ID') . ", " . $helper->quote('TYPE') . ", " . $helper->quote('SONET_LOG_ID') . ")
66 VALUES
67 (". implode("),(", $req) .")
68 ";
69
70 $connection->queryExecute($sql);
71
72 self::$inQueue[$userId] = true;
73 }
74
80 public function get(int $limit): array
81 {
82 if (!empty($this->popped))
83 {
84 throw new CounterQueuePopException();
85 }
86
87 $iterator = QueueTable::getList([
88 'select' => [
89 'ID',
90 'USER_ID',
91 'TYPE',
92 'SONET_LOG_ID',
93 ],
94 'order' => [
95 'ID' => 'ASC',
96 ],
97 'limit' => $limit,
98 ]);
99
100 $queue = [];
101 while ($row = $iterator->fetch())
102 {
103 $this->popped[] = $row['ID'];
104
105 $userId = (int) $row['USER_ID'];
106 $type = $row['TYPE'];
107 $key = $userId.'_'.$type;
108
109 if (!array_key_exists($key, $queue))
110 {
111 $queue[$userId.'_'.$type] = [
112 'USER_ID' => $userId,
113 'TYPE' => $type
114 ];
115 }
116 $queue[$key]['SONET_LOGS'][] = (int) $row['SONET_LOG_ID'];
117 }
118
119 return $queue;
120 }
121
125 public function done(): void
126 {
127 if (empty($this->popped))
128 {
129 return;
130 }
131
132 $connection = Application::getConnection();
133 $helper = $connection->getSqlHelper();
134
135 $sql = "
136 DELETE
137 FROM ". $helper->quote(QueueTable::getTableName()) ."
138 WHERE ID IN (". implode(",", $this->popped) .")
139 ";
140 $connection->queryExecute($sql);
141
142 $this->popped = [];
143 }
144}
return select
Определения access_edit.php:440
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getRow(array $parameters)
Определения datamanager.php:398
add(int $userId, string $type, array $logs)
Определения queue.php:47
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7