Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatactiveusercount.php
1<?
2namespace Bitrix\Im\Update;
3
10
11Loc::loadMessages(__FILE__);
12
13final class ChatActiveUserCount extends Stepper
14{
15 private const OPTION_NAME = "im_chat_active_user_counter";
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 = (
76 SELECT COUNT(1)
77 FROM b_im_relation R
78 LEFT JOIN b_user U ON R.USER_ID = U.ID
79 WHERE R.CHAT_ID = C.ID AND U.ACTIVE = 'Y'
80 )
81 WHERE C.ID IN (" .$implodedIds. ")
82 ORDER BY C.ID ASC
83 LIMIT 100
84 ");
85
86 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
87 $return = true;
88 }
89 else
90 {
91 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
92 }
93
94 $result["steps"] = $params["number"];
95 }
96
97 return $return;
98 }
99}
static loadMessages($file)
Definition loc.php:64