1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
chatindex.php
См. документацию.
1<?
2namespace Bitrix\Im\Update;
3
4use Bitrix\Im\Chat;
5use Bitrix\Im\Model\ChatTable;
6use Bitrix\Main\Update\Stepper;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Loader;
9use Bitrix\Main\Config\Option;
10
11
12Loc::loadMessages(__FILE__);
13
14final class ChatIndex extends Stepper
15{
16 const OPTION_NAME = "im_index_chat";
17
18 protected static $moduleId = "im";
19
23 public function execute(array &$result)
24 {
25 if (!Loader::includeModule(self::$moduleId))
26 {
27 return false;
28 }
29
30 $return = false;
31
32 $params = Option::get(self::$moduleId, $this->getOptionName());
33 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : []);
34 $params = (is_array($params) ? $params : []);
35
36 if (empty($params))
37 {
38 $params = $this->fillNewParams();
39 }
40
41 if ($params["count"] <= 0)
42 {
43 return false;
44 }
45
46 $result["title"] = Loc::getMessage("IM_UPDATE_CHAT_INDEX");
47 $result["progress"] = 1;
48 $result["steps"] = "";
49 $result["count"] = $params["count"];
50
51 $cursor = ChatTable::getList([
52 'order' => ['ID' => 'DESC'],
53 'filter' => [
54 '<ID' => $params["lastId"],
55 '=TYPE' => $this->getTypes(),
56 ],
57 'select' => ['ID', 'ENTITY_TYPE'],
58 'offset' => 0,
59 'limit' => 500
60 ]);
61
62 $found = false;
63 while ($row = $cursor->fetch())
64 {
65 if ($row['ENTITY_TYPE'] !== 'LIVECHAT')
66 {
67 \CIMChat::index($row['ID']);
68 }
69
70 $params["lastId"] = $row['ID'];
71 $params["number"]++;
72 $found = true;
73 }
74
75 if ($found)
76 {
77 Option::set(self::$moduleId, $this->getOptionName(), serialize($params));
78 $return = true;
79 }
80
81 $result["progress"] = (int)($params["number"] * 100 / $params["count"]);
82 $result["steps"] = $params["number"];
83
84 if ($found === false)
85 {
86 $this->sendAdminMessage();
87 }
88
89 return $return;
90 }
91
92 private function fillNewParams(): array
93 {
94 $lastIdQuery =
95 ChatTable::query()
96 ->addSelect('ID')
97 ->whereIn('TYPE', $this->getTypes())
98 ->setOrder(['ID' => 'DESC'])
99 ->setLimit(1)
100 ->fetch()
101 ;
102
103 return [
104 "lastId" => (int)$lastIdQuery['ID'] + 1,
105 "number" => 0,
106 "count" => $this->getChatCount(),
107 ];
108 }
109
110 private function getChatCount(): int
111 {
112 return ChatTable::getCount([
113 '=TYPE' => $this->getTypes(),
114 ]);
115 }
116
117 private function sendAdminMessage(): void
118 {
119 Option::delete(self::$moduleId, ["name" => $this->getOptionName()]);
120 if (!IsModuleInstalled('bitrix24'))
121 {
123 "MESSAGE" => Loc::getMessage(
124 'IM_UPDATE_CHAT_INDEX_OPTIMIZE',
125 ['#B_TAG_START#' => '<b>', '#B_TAG_END#' => '</b>']
126 ),
127 "TAG" => "IM_CHAT_INDEX_OPTIMIZE_1",
128 "MODULE_ID" => "IM",
129 ]);
130 }
131 }
132
133 private function getTypes(): array
134 {
135 $types = [];
136 $defaultTypes = [Chat::TYPE_OPEN, Chat::TYPE_GROUP];
137
138 foreach ($this->getOuterParams() as $type)
139 {
140 $types[] = $type;
141 }
142
143 return !empty($types) ? $types : $defaultTypes;
144 }
145
146 private function getOptionName(): string
147 {
148 $types = $this->getTypes();
149
150 if (empty($this->getOuterParams()))
151 {
152 return self::OPTION_NAME;
153 }
154
155 return self::OPTION_NAME . '_' . implode('_', $types);
156 }
157}
$type
Определения options.php:106
const TYPE_OPEN
Определения chat.php:26
const TYPE_GROUP
Определения chat.php:28
execute(array &$result)
Определения chatindex.php:23
static $moduleId
Определения chatindex.php:18
const OPTION_NAME
Определения chatindex.php:16
getOuterParams()
Определения stepper.php:212
static Add($arFields)
Определения admin_notify.php:22
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
IsModuleInstalled($module_id)
Определения tools.php:5301
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799