1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
7namespace Bitrix\Iblock\PropertyIndex;
8
9use Bitrix\Main\ModuleManager;
10use Bitrix\Main\Loader;
11use Bitrix\Main\Localization\Loc;
12use Bitrix\Iblock;
13
15{
16 private static $catalog = null;
17
18 private static $deferredIndexing = -1;
19
20 private static $elementQueue = array();
21
22 private static $indexerInstances = array();
23
32 public static function resolveIblock($iblockId)
33 {
34 if (self::$catalog === null)
35 {
36 self::$catalog = Loader::includeModule("catalog");
37 }
38
39 if (self::$catalog)
40 {
41 $catalog = \CCatalogSKU::getInfoByOfferIBlock($iblockId);
42 if (!empty($catalog) && is_array($catalog))
43 {
44 return $catalog["PRODUCT_IBLOCK_ID"];
45 }
46 }
47
48 return $iblockId;
49 }
50
60 public static function resolveElement($iblockId, $elementId)
61 {
62 if (self::$catalog === null)
63 {
64 self::$catalog = Loader::includeModule("catalog");
65 }
66
67 if (self::$catalog)
68 {
69 $catalog = \CCatalogSKU::getProductInfo($elementId, $iblockId);
70 if (!empty($catalog) && is_array($catalog))
71 {
72 return $catalog["ID"];
73 }
74 }
75
76 return $elementId;
77 }
78
86 public static function dropIfExists($iblockId)
87 {
89 if ($storage->isExists())
90 $storage->drop();
91
92 $dictionary = new Dictionary($iblockId);
93 if ($dictionary->isExists())
94 $dictionary->drop();
95 }
96
104 public static function createIndexer($iblockId)
105 {
106 $iblockId = (int)$iblockId;
108 if (!isset(self::$indexerInstances[$productIblock]))
109 {
110 $indexer = new Indexer($productIblock);
111 $indexer->init();
112 self::$indexerInstances[$productIblock] = $indexer;
113 unset($indexer);
114 }
115 return self::$indexerInstances[$productIblock];
116 }
117
125 public static function markAsInvalid($iblockId)
126 {
128 "PROPERTY_INDEX" => "I",
129 ));
130
133 {
135 "PROPERTY_INDEX" => "I",
136 ));
137 }
138
140 }
141
151 public static function onPropertyUpdate($iblockId, $propertyOld, $propertyNew)
152 {
153 if (array_key_exists("USER_TYPE", $propertyNew))
154 {
157 if ($storageOld !== $storageNew)
158 {
160 }
161 }
162 }
163
171 public static function checkAdminNotification($force = false)
172 {
173 if ($force)
174 {
175 $add = true;
176 }
177 else
178 {
180 'select' => array('ID'),
181 'filter' => array('=PROPERTY_INDEX' => 'I'),
182 ));
183 $add = (bool)$iblockList->fetch();
184 }
185
186 if (ModuleManager::isModuleInstalled('bitrix24'))
187 {
188 $add = false;
189 }
190
191 if ($add)
192 {
193 $notifyList = \CAdminNotify::getList(array(), array(
194 "TAG" => "iblock_property_reindex",
195 ));
196 if (!$notifyList->fetch())
197 {
198 \CAdminNotify::add(array(
199 "MESSAGE" => Loc::getMessage("IBLOCK_NOTIFY_PROPERTY_REINDEX", array(
200 "#LINK#" => "/bitrix/admin/iblock_reindex.php?lang=".\Bitrix\Main\Application::getInstance()->getContext()->getLanguage(),
201 )),
202 "TAG" => "iblock_property_reindex",
203 "MODULE_ID" => "iblock",
204 "ENABLE_CLOSE" => "Y",
205 "PUBLIC_SECTION" => "N",
206 ));
207 }
208 }
209 else
210 {
211 \CAdminNotify::deleteByTag("iblock_property_reindex");
212 }
213 }
214
221 public static function deleteIndex($iblockId)
222 {
225 "PROPERTY_INDEX" => "N",
226 ));
227 }
228
237 public static function deleteElementIndex($iblockId, $elementId)
238 {
239 $elementId = (int)$elementId;
242
243 if ($indexer->isExists())
244 {
246 {
248 }
249 else
250 {
251 $indexer->deleteElement($elementId);
252 }
253 }
254 }
255
264 public static function updateElementIndex($iblockId, $elementId)
265 {
266 $elementId = (int)$elementId;
269 $elementId = self::resolveElement($iblockId, $elementId);
270 if (self::usedDeferredIndexing())
271 {
272 self::pushToQueue($productIblock, $elementId);
273 }
274 else
275 {
277 if ($indexer->isExists())
278 {
279 self::elementIndexing($indexer, $elementId);
280 }
281 unset($indexer);
282 }
283 }
284
290 public static function enableDeferredIndexing()
291 {
292 self::$deferredIndexing++;
293 }
294
300 public static function disableDeferredIndexing()
301 {
302 self::$deferredIndexing--;
303 }
304
310 public static function usedDeferredIndexing()
311 {
312 return (self::$deferredIndexing >= 0);
313 }
314
321 public static function runDeferredIndexing($iblockId)
322 {
323 $iblockId = (int)$iblockId;
325 if (empty(self::$elementQueue[$productIblock]))
326 return;
328 if ($indexer->isExists())
329 {
330 sort(self::$elementQueue[$productIblock]);
331
332 foreach (self::$elementQueue[$productIblock] as $elementId)
333 self::elementIndexing($indexer, $elementId);
334 unset($elementId);
335 }
336 unset($indexer);
337 unset(self::$elementQueue[$productIblock]);
338 }
339
340 private static function pushToQueue($iblockId, $elementId)
341 {
342 if (!isset(self::$elementQueue[$iblockId]))
343 self::$elementQueue[$iblockId] = [];
344 self::$elementQueue[$iblockId][$elementId] = $elementId;
345 }
346
347 private static function elementIndexing(Iblock\PropertyIndex\Indexer $indexer, $elementId)
348 {
349 $indexer->deleteElement($elementId);
351 $elementCheck = $connection->query("
352 SELECT BE.ID
353 FROM b_iblock_element BE
354 WHERE BE.ACTIVE = 'Y' AND BE.ID = ".$elementId.
355 \CIBlockElement::wf_getSqlLimit("BE.", "N")
356 );
357 if ($elementCheck->fetch())
358 {
359 $indexer->indexElement($elementId);
360 }
361 unset($elementCheck, $connection);
362 }
363}
$connection
Определения actionsdefinitions.php:38
Определения iblock.php:18
static getPropertyStorageType($property)
Определения indexer.php:450
static deleteElementIndex($iblockId, $elementId)
Определения manager.php:237
static checkAdminNotification($force=false)
Определения manager.php:171
static disableDeferredIndexing()
Определения manager.php:300
static markAsInvalid($iblockId)
Определения manager.php:125
static resolveIblock($iblockId)
Определения manager.php:32
static createIndexer($iblockId)
Определения manager.php:104
static dropIfExists($iblockId)
Определения manager.php:86
static deleteIndex($iblockId)
Определения manager.php:221
static updateElementIndex($iblockId, $elementId)
Определения manager.php:264
static onPropertyUpdate($iblockId, $propertyOld, $propertyNew)
Определения manager.php:151
static runDeferredIndexing($iblockId)
Определения manager.php:321
static resolveElement($iblockId, $elementId)
Определения manager.php:60
static enableDeferredIndexing()
Определения manager.php:290
static usedDeferredIndexing()
Определения manager.php:310
static getConnection($name="")
Определения application.php:638
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
static update($primary, array $data)
Определения datamanager.php:1256
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$iblockId
Определения iblock_catalog_edit.php:30
$productIblock
Определения iblock_catalog_edit.php:143
$iblockList
Определения iblock_catalog_list.php:271
if(empty($decryptedData)) $storage
Определения quickway.php:270