- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/classes/general/cml2.php
- Класс: CIBlockCMLImport
- Вызов: CIBlockCMLImport::ImportElements
public function ImportElements($start_time, $interval)
{
global $DB;
$counter = array(
"ADD" => 0,
"UPD" => 0,
"DEL" => 0,
"DEA" => 0,
"ERR" => 0,
"CRC" => 0,
);
if($this->next_step["XML_ELEMENTS_PARENT"])
{
IblockPropertyIndexManager::enableDeferredIndexing();
if ($this->bCatalog)
CatalogProductSku::enableDeferredCalculation();
$this->activeStores = $this->getActiveStores();
$obElement = new CIBlockElement();
$obElement->CancelWFSetMove();
$bWF = Loader::includeModule("workflow");
$filter = [
'PARENT_ID' => $this->next_step['XML_ELEMENTS_PARENT'],
];
if (isset($this->next_step['XML_LAST_ID']))
{
$filter['>ID'] = $this->next_step['XML_LAST_ID'];
}
$rsParents = $this->_xml_file->GetList(
array("ID" => "asc"),
$filter,
array("ID", "LEFT_MARGIN", "RIGHT_MARGIN")
);
while($arParent = $rsParents->Fetch())
{
if (!$arParent["RIGHT_MARGIN"])
continue;
$counter["CRC"]++;
$arXMLElement = $this->_xml_file->GetAllChildrenArray($arParent);
$hashPosition = strrpos($arXMLElement[$this->mess["IBLOCK_XML2_ID"]], "#");
if(!$this->next_step["bOffer"] && $this->use_offers)
{
if($hashPosition !== false)
{
$this->next_step["XML_LAST_ID"] = $arParent["ID"];
continue;
}
}
if(array_key_exists($this->mess["IBLOCK_XML2_STATUS"], $arXMLElement) && ($arXMLElement[$this->mess["IBLOCK_XML2_STATUS"]] == $this->mess["IBLOCK_XML2_DELETED"]))
{
$ID = $this->GetElementByXML_ID($this->next_step["IBLOCK_ID"], $arXMLElement[$this->mess["IBLOCK_XML2_ID"]]);
if($ID && $obElement->Update($ID, array("ACTIVE"=>"N"), $bWF))
{
if($this->use_offers)
$this->ChangeOffersStatus($ID, "N", $bWF);
$counter["DEA"]++;
}
else
{
$counter["ERR"]++;
}
}
elseif(array_key_exists($this->mess["IBLOCK_XML2_BX_TAGS"], $arXMLElement))
{
//This is our export file
$ID = $this->ImportElement($arXMLElement, $counter, $bWF, $arParent);
}
else
{
$this->arFileDescriptionsMap = array();
$this->arElementFilesId = array();
$this->arElementFiles = array();
//offers.xml
if ($this->next_step["bOffer"])
{
if (!$this->use_offers)
{
//We have only one information block
$ID = $this->ImportElementPrices($arXMLElement, $counter, $arParent);
}
elseif ($hashPosition === false && !$this->force_offers)
{
//We have separate offers iblock and there is element price
$ID = $this->ImportElementPrices($arXMLElement, $counter, $arParent);
}
else
{
$xmlKeys = array_keys($arXMLElement);
if ($xmlKeys == array($this->mess["IBLOCK_XML2_ID"], $this->mess["IBLOCK_XML2_PRICES"]))
{
//prices.xml
$ID = $this->ImportElementPrices($arXMLElement, $counter, $arParent);
}
elseif ($xmlKeys == array($this->mess["IBLOCK_XML2_ID"], $this->mess["IBLOCK_XML2_RESTS"]))
{
//rests.xml
$ID = $this->ImportElementPrices($arXMLElement, $counter, $arParent);
}
else
{
//It's an offer in offers iblock
$ID = $this->ImportElement($arXMLElement, $counter, $bWF, $arParent);
}
}
}
//import.xml
else
{
$ID = $this->ImportElement($arXMLElement, $counter, $bWF, $arParent);
}
}
if($ID)
{
$ipropValues = new BitrixIblockInheritedPropertyElementValues($this->next_step["IBLOCK_ID"], $ID);
$ipropValues->clearValues();
$DB->Query("UPDATE b_iblock_element SET TIMESTAMP_X = ".$DB->CurrentTimeFunction()." WHERE ID=".$ID);
$this->_xml_file->Add(array("PARENT_ID" => 0, "LEFT_MARGIN" => $ID));
}
$this->next_step["XML_LAST_ID"] = $arParent["ID"];
if($interval > 0 && (time()-$start_time) > (2*$interval/3))
break;
}
if ($this->bCatalog)
{
CatalogProductSku::disableDeferredCalculation();
CatalogProductSku::calculate();
}
IblockPropertyIndexManager::disableDeferredIndexing();
IblockPropertyIndexManager::runDeferredIndexing($this->next_step["IBLOCK_ID"]);
}
$this->CleanTempFiles();
return $counter;
}