1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
chatinvalidcounter.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\Update;
4
5use Bitrix\Im\Model\MessageUnreadTable;
6use Bitrix\Im\V2\Message\CounterService;
7use Bitrix\Main\Application;
8use Bitrix\Main\Loader;
9use Bitrix\Main\Update\Stepper;
10
11final class ChatInvalidCounter extends Stepper
12{
13 private const ITERATION_COUNT = 5;
14
15 protected static $moduleId = 'im';
16
18 {
19 if (!Loader::includeModule(self::$moduleId))
20 {
21 return self::CONTINUE_EXECUTION;
22 }
23
24 $result = self::CONTINUE_EXECUTION;
25 for ($i = 0; $i < self::ITERATION_COUNT; ++$i)
26 {
27 $result = $this->makeMigrationIteration($option);
28
29 if ($result === self::FINISH_EXECUTION)
30 {
31 return $result;
32 }
33 }
34
35 return $result;
36 }
37
38 private function makeMigrationIteration(array &$option): bool
39 {
40 $lastId = $option['lastId'] ?? 0;
41 $userId = $this->getNextUser($lastId);
42
43 if ($userId === null || $userId === 0)
44 {
45 return self::FINISH_EXECUTION;
46 }
47
48 $option['lastId'] = $userId;
49
50 $chatIds = $this->getChatsWithInvalidCounterByUserId($userId);
51
52 if (empty($chatIds))
53 {
54 return self::CONTINUE_EXECUTION;
55 }
56
57 MessageUnreadTable::deleteByFilter(['=USER_ID' => $userId, '=CHAT_ID' => $chatIds]);
59
60 return self::CONTINUE_EXECUTION;
61 }
62
63 private function getChatsWithInvalidCounterByUserId(int $userId): array
64 {
65 $query = "
66 SELECT x1.CHAT_ID FROM (
67 SELECT bimu.CHAT_ID
68 FROM b_im_message_unread bimu
69 WHERE USER_ID = {$userId} GROUP BY CHAT_ID
70 ) x1
71
72 LEFT JOIN (
73
74 SELECT bir.CHAT_ID
75 FROM b_im_relation bir
76 WHERE
77 bir.USER_ID = {$userId} AND
78 bir.CHAT_ID IN (
79 SELECT bimu.CHAT_ID
80 FROM b_im_message_unread bimu
81 WHERE USER_ID = {$userId} GROUP BY CHAT_ID
82 )
83 ) x2 ON x1.CHAT_ID = x2.CHAT_ID
84
85 WHERE x2.CHAT_ID is null
86 ";
87 $result = Application::getConnection()->query($query);
88 $chatIds = [];
89
90 while ($row = $result->fetch())
91 {
92 $chatIds[] = (int)$row['CHAT_ID'];
93 }
94
95 return $chatIds;
96 }
97
98 private function getNextUser(?int $lastId = null): ?int
99 {
100 $query = MessageUnreadTable::query()
101 ->setSelect(['USER_ID'])
102 ->setGroup(['USER_ID'])
103 ->setOrder(['USER_ID'])
104 ->setLimit(1)
105 ;
106
107 if (isset($lastId) && $lastId > 0)
108 {
109 $query->where('USER_ID', '>', $lastId);
110 }
111
112 $result = $query->fetch();
113
114 if (!$result || !isset($result['USER_ID']))
115 {
116 return null;
117 }
118
119 return (int)$result['USER_ID'];
120 }
121}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
execute(array &$option)
Определения chatinvalidcounter.php:17
static clearCache($moduleId)
Определения option.php:464
if(!\Bitrix\Main\Loader::includeModule('clouds')) $lastId
Определения sync.php:68
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$i
Определения factura.php:643
$option
Определения options.php:1711