16 private static $catalog =
null;
18 private static $deferredIndexing = -1;
20 private static $elementQueue = array();
22 private static $indexerInstances = array();
34 if (self::$catalog ===
null)
36 self::$catalog = Loader::includeModule(
"catalog");
41 $catalog = \CCatalogSKU::getInfoByOfferIBlock($iblockId);
42 if (!empty($catalog) && is_array($catalog))
44 return $catalog[
"PRODUCT_IBLOCK_ID"];
62 if (self::$catalog ===
null)
64 self::$catalog = Loader::includeModule(
"catalog");
69 $catalog = \CCatalogSKU::getProductInfo($elementId, $iblockId);
70 if (!empty($catalog) && is_array($catalog))
72 return $catalog[
"ID"];
88 $storage =
new Storage($iblockId);
89 if ($storage->isExists())
93 if ($dictionary->isExists())
106 $iblockId = (int)$iblockId;
108 if (!isset(self::$indexerInstances[$productIblock]))
110 $indexer =
new Indexer($productIblock);
112 self::$indexerInstances[$productIblock] = $indexer;
115 return self::$indexerInstances[$productIblock];
127 Iblock\IblockTable::update($iblockId, array(
128 "PROPERTY_INDEX" =>
"I",
132 if ($iblockId != $productIblock)
134 Iblock\IblockTable::update($productIblock, array(
135 "PROPERTY_INDEX" =>
"I",
153 if (array_key_exists(
"USER_TYPE", $propertyNew))
155 $storageOld = Iblock\PropertyIndex\Indexer::getPropertyStorageType($propertyOld);
156 $storageNew = Iblock\PropertyIndex\Indexer::getPropertyStorageType($propertyNew);
157 if ($storageOld !== $storageNew)
179 $iblockList = Iblock\IblockTable::getList(array(
180 'select' => array(
'ID'),
181 'filter' => array(
'=PROPERTY_INDEX' =>
'I'),
183 $add = (bool)$iblockList->fetch();
193 $notifyList = \CAdminNotify::getList(array(), array(
194 "TAG" =>
"iblock_property_reindex",
196 if (!$notifyList->fetch())
198 \CAdminNotify::add(array(
202 "TAG" =>
"iblock_property_reindex",
203 "MODULE_ID" =>
"iblock",
204 "ENABLE_CLOSE" =>
"Y",
205 "PUBLIC_SECTION" =>
"N",
211 \CAdminNotify::deleteByTag(
"iblock_property_reindex");
224 Iblock\IblockTable::update($iblockId, array(
225 "PROPERTY_INDEX" =>
"N",
239 $elementId = (int)$elementId;
243 if ($indexer->isExists())
245 if ($iblockId != $productIblock)
251 $indexer->deleteElement($elementId);
266 $elementId = (int)$elementId;
268 if ($iblockId != $productIblock)
270 if (self::usedDeferredIndexing())
272 self::pushToQueue($productIblock, $elementId);
277 if ($indexer->isExists())
279 self::elementIndexing($indexer, $elementId);
292 self::$deferredIndexing++;
302 self::$deferredIndexing--;
312 return (self::$deferredIndexing >= 0);
323 $iblockId = (int)$iblockId;
325 if (empty(self::$elementQueue[$productIblock]))
328 if ($indexer->isExists())
330 sort(self::$elementQueue[$productIblock]);
332 foreach (self::$elementQueue[$productIblock] as $elementId)
333 self::elementIndexing($indexer, $elementId);
337 unset(self::$elementQueue[$productIblock]);
340 private static function pushToQueue($iblockId, $elementId)
342 if (!isset(self::$elementQueue[$iblockId]))
343 self::$elementQueue[$iblockId] = [];
344 self::$elementQueue[$iblockId][$elementId] = $elementId;
347 private static function elementIndexing(
Iblock\PropertyIndex\Indexer $indexer, $elementId)
349 $indexer->deleteElement($elementId);
350 $connection = \Bitrix\Main\Application::getConnection();
351 $elementCheck = $connection->query(
"
353 FROM b_iblock_element BE
354 WHERE BE.ACTIVE = 'Y' AND BE.ID = ".$elementId.
355 \CIBlockElement::wf_getSqlLimit(
"BE.",
"N")
357 if ($elementCheck->fetch())
359 $indexer->indexElement($elementId);
361 unset($elementCheck, $connection);
static deleteElementIndex($iblockId, $elementId)
static checkAdminNotification($force=false)
static disableDeferredIndexing()
static markAsInvalid($iblockId)
static resolveIblock($iblockId)
static createIndexer($iblockId)
static dropIfExists($iblockId)
static deleteIndex($iblockId)
static updateElementIndex($iblockId, $elementId)
static onPropertyUpdate($iblockId, $propertyOld, $propertyNew)
static runDeferredIndexing($iblockId)
static resolveElement($iblockId, $elementId)
static enableDeferredIndexing()
static usedDeferredIndexing()
static getMessage($code, $replace=null, $language=null)
static isModuleInstalled($moduleName)