Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatstartingcount.php
1<?
2namespace Bitrix\Im\Update;
3
9
10Loc::loadMessages(__FILE__);
11
12final class ChatStartingCount extends Stepper
13{
14 private const OPTION_NAME = "im_chat_starting_counter";
15
16 protected static $moduleId = "im";
17
21 public function execute(array &$result)
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" => RelationTable::getCount(),
41 ];
42 }
43
44 if ($params["count"] > 0)
45 {
46 $result["steps"] = "";
47 $result["count"] = $params["count"];
48
49 $ids = RelationTable::getList(
50 [
51 'order' => ['ID' => 'ASC'],
52 'filter' => [
53 '>ID' => $params["lastId"],
54 '>START_ID' => 0
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_relation R
75 INNER JOIN b_im_chat C ON R.CHAT_ID = C.ID
76 SET R.START_COUNTER = (
77 SELECT COUNT(1)
78 FROM b_im_message M
79 WHERE M.CHAT_ID = R.CHAT_ID AND M.ID < R.START_ID
80 )
81 WHERE R.ID IN (" .$implodedIds. ")
82 ");
83
84 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
85 $return = true;
86 }
87 else
88 {
89 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
90 }
91
92 $result["steps"] = $params["number"];
93 }
94
95 return $return;
96 }
97}
static loadMessages($file)
Definition loc.php:64