Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
reindexprocess.php
1<?
10
11use Bitrix\Main;
12
14
16{
17 const DEBUG_MODE = true;
18
19 protected $sessionKey = 'location_reindex';
20
21 protected $wordInstance = null;
22 protected $chainInstance = null;
23
24 public function __construct($options)
25 {
26 $this->addStage(array(
27 'PERCENT' => 5,
28 'CODE' => 'CLEANUP',
29 'CALLBACK' => 'stageCleanup'
30 ));
31
32 $this->addStage(array(
33 'PERCENT' => 10,
34 'CODE' => 'CREATE_DICTIONARY',
35 'CALLBACK' => 'stageCreateDictionary',
36 'SUBPERCENT_CALLBACK' => 'getSubpercentForStageCreateDictionary',
37 'ON_BEFORE_CALLBACK' => 'stageCreateDictionaryBefore',
38 'ON_AFTER_CALLBACK' => 'stageCreateDictionaryAfter',
39 'TYPE' => static::CALLBACK_TYPE_QUOTA
40 ));
41
42 $this->addStage(array(
43 'PERCENT' => 20,
44 'CODE' => 'RESORT_DICTIONARY',
45 'CALLBACK' => 'stageResortDictionary',
46 'SUBPERCENT_CALLBACK' => 'getSubpercentForStageResortDictionary',
47 'ON_BEFORE_CALLBACK' => 'stageResortDictionaryBefore',
48 'ON_AFTER_CALLBACK' => 'stageResortDictionaryAfter',
49 'TYPE' => static::CALLBACK_TYPE_QUOTA
50 ));
51
52 $this->addStage(array(
53 'PERCENT' => 80,
54 'CODE' => 'CREATE_SEARCH_INDEX',
55 'CALLBACK' => 'stageCreateSearchIndex',
56 'SUBPERCENT_CALLBACK' => 'getSubpercentForStageCreateSearchIndex',
57 'ON_BEFORE_CALLBACK' => 'stageCreateSearchIndexBefore',
58 'ON_AFTER_CALLBACK' => 'stageCreateSearchIndexAfter',
59 'TYPE' => static::CALLBACK_TYPE_QUOTA
60 ));
61
62 $this->addStage(array(
63 'PERCENT' => 90,
64 'CODE' => 'CREATE_SITE2LOCATION_INDEX',
65 'CALLBACK' => 'stageCreateSite2LocationIndex',
66 'SUBPERCENT_CALLBACK' => 'getSubpercentForCreateSite2LocationIndex'
67 ));
68
69 $this->addStage(array(
70 'PERCENT' => 100,
71 'CODE' => 'RESTORE_DB_INDEXES',
72 'CALLBACK' => 'stageRestoreDBIndexes',
73 'SUBPERCENT_CALLBACK' => 'getSubpercentForRestoreDBIndexes'
74 ));
75
76 parent::__construct($options);
77 }
78
79 public function onAfterPerformIteration()
80 {
81 if($this->getPercent() == 100)
83 }
84
86 // STAGES
87
88 protected function stageCleanup()
89 {
91
95
96 $this->nextStage();
97 }
98
100
101 protected function stageCreateDictionaryBefore()
102 {
103 if(!isset($this->data['WORD_TABLE_INSTANCE_SERIALIZED']))
104 {
105 $instance = new WordTable(array(
106 'TYPES' => Finder::getIndexedTypes(),
107 'LANGS' => Finder::getIndexedLanguages()
108 ));
109 }
110 else
111 {
112 $instance = unserialize(
113 $this->data['WORD_TABLE_INSTANCE_SERIALIZED'],
114 ['allowed_classes' => [WordTable::class]]
115 );
116 }
117
118 $this->wordInstance = $instance;
119 }
120
121 protected function stageCreateDictionary()
122 {
123 if($this->getStep() == 0)
124 {
125 $this->wordInstance->setOffset(0);
126 $this->wordInstance->setPosition(0);
127 }
128
129 return $this->wordInstance->initializeData();
130 }
131
132 protected function stageCreateDictionaryAfter()
133 {
134 $this->data['WORD_TABLE_INSTANCE_SERIALIZED'] = serialize($this->wordInstance);
135 $this->data['OFFSET'] = $this->wordInstance->getOffset();
136 }
137
139 {
140 if(!isset($this->data['LOC_NAMES_2_INDEX_COUNT']))
141 {
142 $item = Location\Name\LocationTable::getList(array(
143 'select' => array('CNT'),
144 'filter' => WordTable::getFilterForInitData(array(
145 'TYPES' => Finder::getIndexedTypes(),
146 'LANGS' => Finder::getIndexedLanguages()
147 ))
148 ))->fetch();
149
150 $this->data['LOC_NAMES_2_INDEX_COUNT'] = intval($item['CNT']);
151 }
152
153 return $this->getSubPercentByTotalAndDone($this->data['LOC_NAMES_2_INDEX_COUNT'], $this->data['OFFSET'] ?? 0);
154 }
155
157
158 protected function stageResortDictionaryBefore()
159 {
160 if(!isset($this->data['WORD_TABLE_INSTANCE_SERIALIZED']))
161 {
162 $instance = new WordTable(array(
163 'TYPES' => Finder::getIndexedTypes(),
164 'LANGS' => Finder::getIndexedLanguages()
165 ));
166 }
167 else
168 $instance = unserialize(
169 $this->data['WORD_TABLE_INSTANCE_SERIALIZED'],
170 ['allowed_classes' => [WordTable::class]]
171 );
172
173 $this->wordInstance = $instance;
174 }
175
176 protected function stageResortDictionary()
177 {
178 if($this->getStep() == 0)
179 {
180 $this->wordInstance->setOffset(0);
181 $this->wordInstance->setPosition(0);
182 }
183
184 $allDone = $this->wordInstance->resort();
185
186 if($allDone)
187 $this->wordInstance->mergeResort();
188
189 return $allDone;
190 }
191
192 protected function stageResortDictionaryAfter()
193 {
194 $this->data['WORD_TABLE_INSTANCE_SERIALIZED'] = serialize($this->wordInstance);
195 $this->data['OFFSET'] = $this->wordInstance->getOffset();
196 }
197
199 {
200 if($this->getStep() == 0)
201 $this->data['OFFSET'] = 0;
202
203 if(!isset($this->data['DICTIONARY_SIZE']))
204 {
205 $item = WordTable::getList(array(
206 'select' => array('CNT')
207 ))->fetch();
208
209 $this->data['DICTIONARY_SIZE'] = intval($item['CNT']);
210 }
211
212 return $this->getSubPercentByTotalAndDone($this->data['DICTIONARY_SIZE'], $this->data['OFFSET']);
213 }
214
216
217 protected function stageCreateSearchIndexBefore()
218 {
219 if(!isset($this->data['CHAIN_TABLE_INSTANCE_SERIALIZED']))
220 {
221 $instance = new ChainTable(array(
222 'TYPES' => Finder::getIndexedTypes()
223 ));
224 }
225 else
226 $instance = unserialize(
227 $this->data['CHAIN_TABLE_INSTANCE_SERIALIZED'],
228 ['allowed_classes' => [ChainTable::class]]
229 );
230
231 $this->chainInstance = $instance;
232 }
233
234 protected function stageCreateSearchIndex()
235 {
236 return $this->chainInstance->initializeData();
237 }
238
239 protected function stageCreateSearchIndexAfter()
240 {
241 $this->data['CHAIN_TABLE_INSTANCE_SERIALIZED'] = serialize($this->chainInstance);
242 $this->data['OFFSET'] = $this->chainInstance->getOffset();
243 }
244
246 {
247 if($this->getStep() == 0)
248 $this->data['OFFSET'] = 0;
249
250 if(!isset($this->data['INDEX_LOCATION_COUNT']))
251 {
252 $item = Location\LocationTable::getList(array(
253 'select' => array(
254 'CNT'
255 ),
256 'filter' => ChainTable::getFilterForInitData(array('TYPES' => Finder::getIndexedTypes()))
257 ))->fetch();
258
259 $this->data['INDEX_LOCATION_COUNT'] = intval($item['CNT']);
260 }
261
262 return $this->getSubPercentByTotalAndDone($this->data['INDEX_LOCATION_COUNT'], $this->data['OFFSET']);
263 }
264
266
267 protected function stageCreateSite2LocationIndex()
268 {
270
271 $this->nextStage();
272 }
274 {
275 return 0;
276 }
277
278 protected function stageRestoreDBIndexes()
279 {
280 $step = $this->getStep();
281
282 if($step == 0)
284 elseif($step == 1)
286 elseif($step == 2)
288
289 if($step >= 2)
290 $this->nextStage();
291 else
292 $this->nextStep();
293 }
295 {
296 $pRange = $this->getCurrentPercentRange();
297 $step = $this->getStep();
298
299 $indexCount = 3;
300
301 if($step >= $indexCount)
302 return $pRange;
303 else
304 {
305 return round($pRange * ($step / $indexCount));
306 }
307 }
308}
static getFilterForInitData($parameters=array())
Definition chain.php:150
static getFilterForInitData($parameters=array())
Definition word.php:263
getSubPercentByTotalAndDone($total, $done=0)
Definition process.php:383