• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/import/import.php
  • Класс: BitrixSaleLocationImportis
  • Вызов: is::stageIntegrityPreserve
protected function stageIntegrityPreserve()
{
	$lay = $this->getRemoteLayout(true);

	$this->restoreIndexes('IX_B_SALE_LOC_PARENT');

	$res = LocationLocationTable::getList(array(
		'select' => array(
			'ID', 'CODE'
		),
		'filter' => array(
			'=PARENT_ID' => 0
		)
	));
	$relations = array();
	$code2id = array();
	while($item = $res->fetch())
	{
		if(isset($lay[$item['CODE']]))
			$relations[$item['CODE']] = $lay[$item['CODE']]['PARENT_CODE'];

		$code2id[$item['CODE']] = $item['ID'];
	}

	$parentCode2id = $this->getLocationCodeToIdMap($relations);

	foreach($code2id as $code => $id)
	{
		if(isset($parentCode2id[$relations[$code]])) // parent really exists
		{
			$res = LocationLocationTable::update($id, array('PARENT_ID' => $parentCode2id[$relations[$code]]));
			if(!$res->isSuccess())
				throw new MainSystemException('Cannot make element become a child of its legal parent');
		}
	}

	$this->nextStage();
}