9 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
10 $users = $connection->query(
"
11 SELECT AUTHOR_ID, COUNT(1) CNT
13 WHERE TYPE = '".IM_MESSAGE_SYSTEM.
"'
18 while ($userData = $users->fetch())
23 $chats = $connection->query(
"
24 SELECT ID, LAST_MESSAGE_ID
26 WHERE TYPE = '".IM_MESSAGE_SYSTEM.
"' AND AUTHOR_ID = ".intval($userData[
'AUTHOR_ID']).
"
28 while ($chatData = $chats->fetch())
30 $result[intval($chatData[
'ID'])] = intval($chatData[
'LAST_MESSAGE_ID']);
33 $result = array_slice($result, 1,
null,
true);
34 $chatId = array_keys($result);
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).
")");
42 return $hasDuplicate?
"\Bitrix\Im\Update\Notify::removeDuplicateChatAgent();":
"";