Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messageindex.php
1<?
2namespace Bitrix\Im\Update;
3
9
10Loc::loadMessages(__FILE__);
11
12final class MessageIndex extends Stepper
13{
14 const OPTION_NAME = "im_index_message";
15 const STATUS_ENABLED = 'enabled';
16 const STATUS_DISABLED = 'disabled';
17 const STATUS_DEFAULT = 'default';
18
19 protected static $moduleId = "im";
20
24 public function execute(array &$result)
25 {
26 global $DB;
27
28 if (!Loader::includeModule(self::$moduleId))
29 {
30 return false;
31 }
32
33 $indexStatus = Option::get(self::$moduleId, self::OPTION_NAME.'_status', self::STATUS_DEFAULT);
34 if ($indexStatus === self::STATUS_DEFAULT)
35 {
36 if (IsModuleInstalled('bitrix24'))
37 {
38 return false;
39 }
40 }
41 elseif ($indexStatus === self::STATUS_DISABLED)
42 {
43 return false;
44 }
45
46 $return = false;
47
48 $params = Option::get(self::$moduleId, self::OPTION_NAME, "");
49 $params = ($params !== "" ? @unserialize($params, ["allowed_classes" => false]) : []);
50 $params = (is_array($params) ? $params : []);
51 if (empty($params))
52 {
53 $params = [
54 "lastId" => 0,
55 "number" => 0,
56 "count" => MessageTable::getCount(),
57 ];
58 }
59
60 if ($params["count"] > 0)
61 {
62 $result["title"] = Loc::getMessage("IM_UPDATE_MESSAGE_INDEX");
63 $result["progress"] = 1;
64 $result["steps"] = "";
65 $result["count"] = $params["count"];
66
67 $cursor = MessageTable::getList(
68 [
69 'order' => ['ID' => 'ASC'],
70 'filter' => [
71 '>ID' => $params["lastId"],
72 ],
73 'select' => ['ID'],
74 'offset' => 0,
75 'limit' => 5000
76 ]
77 );
78
79 $found = false;
80 while ($row = $cursor->fetch())
81 {
82 MessageTable::indexRecord($row['ID']);
83
84 $params["lastId"] = $row['ID'];
85 $params["number"]++;
86 $found = true;
87 }
88
89 if ($found)
90 {
91 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
92 $return = true;
93 }
94
95 $result["progress"] = (int)($params["number"] * 100 / $params["count"]);
96 $result["steps"] = $params["number"];
97
98 if ($found === false)
99 {
100 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
101
102 if ($DB->IndexExists("b_im_message_index", array("SEARCH_CONTENT"), true))
103 {
104 \Bitrix\Im\Model\MessageIndexTable::getEntity()->enableFullTextIndex('SEARCH_CONTENT');
105 }
106 }
107 }
108 elseif ($params["count"] == 0)
109 {
110 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
111
112 if ($DB->IndexExists("b_im_message_index", array("SEARCH_CONTENT"), true))
113 {
114 \Bitrix\Im\Model\MessageIndexTable::getEntity()->enableFullTextIndex('SEARCH_CONTENT');
115 }
116 }
117
118 return $return;
119 }
120}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29