Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatmessagecount.php
1<?php
2namespace Bitrix\Im\Update;
3
9
10Loc::loadMessages(__FILE__);
11
12final class ChatMessageCount extends Stepper
13{
14 private const OPTION_NAME = "im_chat_message_count";
15
16 protected static $moduleId = "im";
17
21 public function execute(array &$result): bool
22 {
23 global $DB;
24
25 if (!Loader::includeModule(self::$moduleId))
26 {
27 return false;
28 }
29
30 $return = false;
31
32 $params = Option::get(self::$moduleId, self::OPTION_NAME, "");
33 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : []);
34 $params = (is_array($params) ? $params : []);
35 if (empty($params))
36 {
37 $params = [
38 "lastId" => 0,
39 "number" => 0,
40 "count" => ChatTable::getCount(),
41 ];
42 }
43
44 if ($params["count"] > 0)
45 {
46 $result["steps"] = "";
47 $result["count"] = $params["count"];
48
49 $ids = ChatTable::getList(
50 [
51 'order' => ['ID' => 'ASC'],
52 'filter' => [
53 '>ID' => $params["lastId"],
54 ],
55 'select' => ['ID'],
56 'offset' => 0,
57 'limit' => 100
58 ]
59 )->fetchAll();
60
61 $ids = array_map(
62 static function($item) {
63 return $item['ID'];
64 },
65 $ids
66 );
67
68 $idsCount = count($ids);
69 if ($idsCount > 0)
70 {
71 $params["lastId"] = $ids[$idsCount - 1];
72 $params["number"] += $idsCount;
73
74 $implodedIds = implode(',', $ids);
75 $DB->Query("
76 UPDATE b_im_chat C
77 SET C.MESSAGE_COUNT = (SELECT COUNT(1) FROM b_im_message M WHERE M.CHAT_ID = C.ID)
78 WHERE C.ID IN (" .$implodedIds. ")
79 ORDER BY C.ID ASC
80 LIMIT 100
81 ");
82
83 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
84 $return = true;
85 }
86 else
87 {
88 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
89 }
90
91 $result["steps"] = $params["number"];
92 }
93
94 return $return;
95 }
96}
static loadMessages($file)
Definition loc.php:64