Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notify.php
1<?php
2namespace Bitrix\Im\Update;
3
4class Notify
5{
6 public static function removeDuplicateChatAgent()
7 {
8 $hasDuplicate = false;
9 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
10 $users = $connection->query("
11 SELECT AUTHOR_ID, COUNT(1) CNT
12 FROM b_im_chat
13 WHERE TYPE = '".IM_MESSAGE_SYSTEM."'
14 GROUP BY AUTHOR_ID
15 HAVING CNT > 1
16 LIMIT 100
17 ");
18 while ($userData = $users->fetch())
19 {
20 $hasDuplicate = true;
21
22 $result = Array();
23 $chats = $connection->query("
24 SELECT ID, LAST_MESSAGE_ID
25 FROM b_im_chat
26 WHERE TYPE = '".IM_MESSAGE_SYSTEM."' AND AUTHOR_ID = ".intval($userData['AUTHOR_ID'])."
27 ");
28 while ($chatData = $chats->fetch())
29 {
30 $result[intval($chatData['ID'])] = intval($chatData['LAST_MESSAGE_ID']);
31 }
32 arsort($result);
33 $result = array_slice($result, 1, null, true);
34 $chatId = array_keys($result);
35 if (!empty($chatId))
36 {
37 $connection->query("DELETE FROM b_im_relation WHERE CHAT_ID IN (".implode(", ", $chatId).")");
38 $connection->query("DELETE FROM b_im_chat WHERE ID IN (".implode(", ", $chatId).")");
39 }
40 }
41
42 return $hasDuplicate? "\Bitrix\Im\Update\Notify::removeDuplicateChatAgent();": "";
43 }
44}
static removeDuplicateChatAgent()
Definition notify.php:6