Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
chatindex.php
1<?
2namespace Bitrix\Im\Update;
3
10
11
12Loc::loadMessages(__FILE__);
13
14final class ChatIndex extends Stepper
15{
16 const OPTION_NAME = "im_index_chat";
17 protected static $moduleId = "im";
18
22 public function execute(array &$result)
23 {
24 if (!Loader::includeModule(self::$moduleId))
25 {
26 return false;
27 }
28
29 $return = false;
30
31 $params = Option::get(self::$moduleId, self::OPTION_NAME, "");
32 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : []);
33 $params = (is_array($params) ? $params : []);
34
35 if (empty($params))
36 {
37 $lastIdQuery =
38 ChatTable::query()
39 ->addSelect('ID')
40 ->whereIn('TYPE', [Chat::TYPE_OPEN, Chat::TYPE_GROUP])
41 ->setOrder(['ID' => 'DESC'])
42 ->setLimit(1)
43 ->fetch()
44 ;
45 $params = [
46 "lastId" => (int)$lastIdQuery['ID'] + 1,
47 "number" => 0,
48 "count" => ChatTable::getCount([
50 ]),
51 ];
52 }
53
54 if ($params["count"] > 0)
55 {
56 $result["title"] = Loc::getMessage("IM_UPDATE_CHAT_INDEX");
57 $result["progress"] = 1;
58 $result["steps"] = "";
59 $result["count"] = $params["count"];
60
61 $cursor = ChatTable::getList([
62 'order' => ['ID' => 'DESC'],
63 'filter' => [
64 '<ID' => $params["lastId"],
66 ],
67 'select' => ['ID', 'ENTITY_TYPE'],
68 'offset' => 0,
69 'limit' => 500
70 ]);
71
72 $found = false;
73 while ($row = $cursor->fetch())
74 {
75 if ($row['ENTITY_TYPE'] != 'LIVECHAT')
76 {
77 \CIMChat::index($row['ID']);
78 }
79
80 $params["lastId"] = $row['ID'];
81 $params["number"]++;
82 $found = true;
83 }
84
85 if ($found)
86 {
87 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
88 $return = true;
89 }
90
91 $result["progress"] = intval($params["number"] * 100/ $params["count"]);
92 $result["steps"] = $params["number"];
93
94 if ($found === false)
95 {
96 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
97 if (!IsModuleInstalled('bitrix24'))
98 {
99 \CAdminNotify::Add([
100 "MESSAGE" => Loc::getMessage(
101 'IM_UPDATE_CHAT_INDEX_OPTIMIZE',
102 ['#B_TAG_START#' => '<b>', '#B_TAG_END#' => '</b>']
103 ),
104 "TAG" => "IM_CHAT_INDEX_OPTIMIZE_1",
105 "MODULE_ID" => "IM",
106 ]);
107 }
108 }
109 }
110 return $return;
111 }
112}
113?>
const TYPE_OPEN
Definition chat.php:22
const TYPE_GROUP
Definition chat.php:24
execute(array &$result)
Definition chatindex.php:22
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29