1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
topic.php
См. документацию.
1<?php
2
3namespace Bitrix\Forum\Integration\Search;
4
5use Bitrix\Forum;
6use Bitrix\Main;
7
9{
10 protected static $moduleId = 'forum';
11
12 public static function getTitle()
13 {
14 return 'Reindex topic';
15 }
16
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 {
36 return self::FINISH_EXECUTION;
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 (
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 {
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
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']);
130 return self::FINISH_EXECUTION;
131 }
132 Main\Config\Option::set('forum', 'search.reindex.topic', serialize($topicsToReindex));
133 return self::CONTINUE_EXECUTION;
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 if (!IsModuleInstalled('search'))
144 {
145 return self::FINISH_EXECUTION;
146 }
147
148 $storedInformation = Main\Config\Option::get('forum', 'search.reindex.topic', '');
149 $topicsToReindex = [];
150
151 if (
152 !empty($storedInformation)
153 && ($res = unserialize($storedInformation, ['allowed_classes' => false]))
154 && is_array($res)
155 )
156 {
157 $topicsToReindex = $res;
158 }
159
160 $topicsToReindex[$topicId] = ['id' => $topicId] + ($reindexOnlyFirstMessage === true ? ['reindexFirst' => true] : []);
161
162 Main\Config\Option::set('forum', 'search.reindex.topic', serialize($topicsToReindex));
163 static::bind(0);
164 }
165
166 public static function deleteIndex(Forum\Topic $topic)
167 {
168 if (IsModuleInstalled('search') && \CModule::IncludeModule('search'))
169 {
170 \CSearch::DeleteIndex('forum', false, $topic['FORUM_ID'], $topic['ID']);
171 }
172 }
173}
$count
Определения admin_tab.php:4
static reindexFirstMessage(int $topicId)
Определения topic.php:136
static reindex(int $topicId, bool $reindexOnlyFirstMessage=false)
Определения topic.php:141
execute(array &$option)
Определения topic.php:20
static deleteIndex(Forum\Topic $topic)
Определения topic.php:166
static getTitle()
Определения topic.php:12
static delete($moduleId, array $filter=array())
Определения option.php:388
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
static includeModule($moduleName)
Определения loader.php:67
static Reindex($ID, &$arMessage=[])
Определения message.php:429
static DeleteIndex($MODULE_ID, $ITEM_ID=false, $PARAM1=false, $PARAM2=false, $SITE_ID=false)
Определения search.php:2922
static GetList($arOrder=Array("ID"=>"ASC"), $arFilter=Array(), $bCount=false, $iNum=0, $arAddParams=array())
Определения message.php:193
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
IsModuleInstalled($module_id)
Определения tools.php:5301
$message
Определения payment.php:8
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$messages
Определения template.php:8
$option
Определения options.php:1711
$dbRes
Определения yandex_detail.php:168