22 $storedInformation = Main\Config\Option::get(
'forum',
'search.reindex.topic',
'');
23 $topicsToReindex = [];
26 !empty($storedInformation)
27 && ($topics = unserialize($storedInformation, [
'allowed_classes' =>
false]))
31 $topicsToReindex = $topics;
34 if (empty($topicsToReindex) || !Main\Loader::includeModule(
'search'))
39 $state = reset($topicsToReindex);
40 $topicId = $state[
'id'] ?? key($topicsToReindex);
43 if (is_array($state) && $topicId > 0)
45 $state[
'reindexFirst'] = ($state[
'reindexFirst'] ??
false) ===
true;
47 if ($state[
'reindexFirst'] ===
true)
50 ($dbRes = \CForumMessage::GetList(
53 'TOPIC_ID' => $topicId,
55 'GET_TOPIC_INFO' =>
'Y',
56 'GET_FORUM_INFO' =>
'Y',
60 && ($message = $dbRes->fetch())
63 \CForumMessage::Reindex($message[
'ID'], $message);
68 $state[
'LAST_ID'] = (int) ($state[
'LAST_ID'] ?? 0);
69 if ($state[
'LAST_ID'] <= 0)
71 \CSearch::DeleteIndex(
'forum',
false,
false, $topicId);
74 $limit = Main\Config\Option::get(
'forum',
'search_message_count', 20);
75 $limit = ($limit > 0 ? $limit : 20);
77 $messages = Forum\MessageTable::query()
79 ->addFilter(
'=TOPIC_ID', $topicId)
80 ->addFilter(
'>ID', $state[
'LAST_ID'])
82 ->setOrder([
'ID' =>
'ASC'])
86 if ($message = $messages->fetch())
88 $forum = Forum\Forum::getById($message[
'FORUM_ID']);
90 if ($forum[
'INDEXATION'] ===
'Y')
92 $topic = Forum\Topic::getById($message[
'TOPIC_ID']);
98 $message[
'FORUM_INFO'] = $forum->getData();
99 $message[
'TOPIC_INFO'] = $topic->getData();
101 \CForumMessage::Reindex($message[
'ID'], $message);
103 $state[
'LAST_ID'] = $message[
'ID'];
105 }
while ($message = $messages->fetch());
107 if ($count >= $limit)
116 if ($result === self::FINISH_EXECUTION)
118 array_shift($topicsToReindex);
122 $topicsToReindex[$topicId] = $state;
124 $option[
'steps'] = 1;
125 $option[
'count'] = count($topicsToReindex);
127 if (empty($topicsToReindex))
129 Main\Config\Option::delete(
'forum', [
'name' =>
'search.reindex.topic']);
132 Main\Config\Option::set(
'forum',
'search.reindex.topic', serialize($topicsToReindex));
141 public static function reindex(
int $topicId,
bool $reindexOnlyFirstMessage =
false)
143 $storedInformation = Main\Config\Option::get(
'forum',
'search.reindex.topic',
'');
144 $topicsToReindex = [];
147 !empty($storedInformation)
148 && ($res = unserialize($storedInformation, [
'allowed_classes' =>
false]))
152 $topicsToReindex = $res;
155 $topicsToReindex[$topicId] = [
'id' => $topicId] + ($reindexOnlyFirstMessage ===
true ? [
'reindexFirst' =>
true] : []);
157 Main\Config\Option::set(
'forum',
'search.reindex.topic', serialize($topicsToReindex));