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