Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
topic.php
1<?php
2
4
7
9{
10 protected static $moduleId = 'forum';
11
12 public static function getTitle()
13 {
14 return 'Reindex topic';
15 }
16
20 function execute(array &$option)
21 {
22 $storedInformation = Main\Config\Option::get('forum', 'search.reindex.topic', '');
23 $topicsToReindex = [];
24
25 if (
26 !empty($storedInformation)
27 && ($topics = unserialize($storedInformation, ['allowed_classes' => false]))
28 && is_array($topics)
29 )
30 {
31 $topicsToReindex = $topics;
32 }
33
34 if (empty($topicsToReindex) || !Main\Loader::includeModule('search'))
35 {
37 }
38
39 $state = reset($topicsToReindex);
40 $topicId = $state['id'] ?? key($topicsToReindex);
41 $result = self::FINISH_EXECUTION;
42
43 if (is_array($state) && $topicId > 0)
44 {
45 $state['reindexFirst'] = ($state['reindexFirst'] ?? false) === true;
46
47 if ($state['reindexFirst'] === true)
48 {
49 if (
50 ($dbRes = \CForumMessage::GetList(
51 ['ID' => 'ASC'],
52 [
53 'TOPIC_ID' => $topicId,
54 'NEW_TOPIC' => 'Y',
55 'GET_TOPIC_INFO' => 'Y',
56 'GET_FORUM_INFO' => 'Y',
57 'FILTER' => 'Y'
58 ]
59 ))
60 && ($message = $dbRes->fetch())
61 )
62 {
63 \CForumMessage::Reindex($message['ID'], $message);
64 }
65 }
66 else
67 {
68 $state['LAST_ID'] = (int) ($state['LAST_ID'] ?? 0);
69 if ($state['LAST_ID'] <= 0)
70 {
71 \CSearch::DeleteIndex('forum', false, false, $topicId);
72 }
73
74 $limit = Main\Config\Option::get('forum', 'search_message_count', 20);
75 $limit = ($limit > 0 ? $limit : 20);
76
77 $messages = Forum\MessageTable::query()
78 ->setSelect(['*'])
79 ->addFilter('=TOPIC_ID', $topicId)
80 ->addFilter('>ID', $state['LAST_ID'])
81 ->setLimit($limit)
82 ->setOrder(['ID' => 'ASC'])
83 ->exec()
84 ;
85
86 if ($message = $messages->fetch())
87 {
88 $forum = Forum\Forum::getById($message['FORUM_ID']);
89
90 if ($forum['INDEXATION'] === 'Y')
91 {
92 $topic = Forum\Topic::getById($message['TOPIC_ID']);
93 $count = 0;
94
95 do
96 {
97 $count++;
98 $message['FORUM_INFO'] = $forum->getData();
99 $message['TOPIC_INFO'] = $topic->getData();
100
101 \CForumMessage::Reindex($message['ID'], $message);
102
103 $state['LAST_ID'] = $message['ID'];
104
105 } while ($message = $messages->fetch());
106
107 if ($count >= $limit)
108 {
109 $result = self::CONTINUE_EXECUTION;
110 }
111 }
112 }
113 }
114 }
115
116 if ($result === self::FINISH_EXECUTION)
117 {
118 array_shift($topicsToReindex);
119 }
120 else
121 {
122 $topicsToReindex[$topicId] = $state;
123 }
124 $option['steps'] = 1;
125 $option['count'] = count($topicsToReindex);
126
127 if (empty($topicsToReindex))
128 {
129 Main\Config\Option::delete('forum', ['name' => 'search.reindex.topic']);
131 }
132 Main\Config\Option::set('forum', 'search.reindex.topic', serialize($topicsToReindex));
134 }
135
136 public static function reindexFirstMessage(int $topicId)
137 {
138 static::reindex($topicId, true);
139 }
140
141 public static function reindex(int $topicId, bool $reindexOnlyFirstMessage = false)
142 {
143 $storedInformation = Main\Config\Option::get('forum', 'search.reindex.topic', '');
144 $topicsToReindex = [];
145
146 if (
147 !empty($storedInformation)
148 && ($res = unserialize($storedInformation, ['allowed_classes' => false]))
149 && is_array($res)
150 )
151 {
152 $topicsToReindex = $res;
153 }
154
155 $topicsToReindex[$topicId] = ['id' => $topicId] + ($reindexOnlyFirstMessage === true ? ['reindexFirst' => true] : []);
156
157 Main\Config\Option::set('forum', 'search.reindex.topic', serialize($topicsToReindex));
158 static::bind(0);
159 }
160
161 public static function deleteIndex(Forum\Topic $topic)
162 {
163 if (IsModuleInstalled('search') && \CModule::IncludeModule('search'))
164 {
165 \CSearch::DeleteIndex('forum', false, $topic['FORUM_ID'], $topic['ID']);
166 }
167 }
168}
static reindexFirstMessage(int $topicId)
Definition topic.php:136
static reindex(int $topicId, bool $reindexOnlyFirstMessage=false)
Definition topic.php:141
static deleteIndex(Forum\Topic $topic)
Definition topic.php:161