• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/import/import.php
  • Класс: BitrixSaleLocationImportis
  • Вызов: is::stageProcessFiles
protected function stageProcessFiles()
{
	if($this->dbConnType == self::DB_TYPE_ORACLE)
		$mtu = self::INSERTER_MTU_ORACLE;
	else
		$mtu = self::INSERTER_MTU;

	$this->hitData['HANDLES']['LOCATION'] = new LocationDBBlockInserter(array(
		'entityName' => 'BitrixSaleLocationLocationTable',
		'exactFields' => array('CODE', 'TYPE_ID', 'PARENT_ID', 'LATITUDE', 'LONGITUDE'),
		'parameters' => array(
			'autoIncrementFld' => 'ID',
			'mtu' => $mtu
		)
	));

	$this->hitData['HANDLES']['NAME'] = new LocationDBBlockInserter(array(
		'entityName' => 'BitrixSaleLocationNameLocationTable',
		'exactFields' => array('NAME', 'NAME_UPPER', 'LANGUAGE_ID', 'LOCATION_ID'),
		'parameters' => array(
			'mtu' => $mtu
		)
	));

	$this->hitData['HANDLES']['EXTERNAL'] = new LocationDBBlockInserter(array(
		'entityName' => 'BitrixSaleLocationExternalTable',
		'exactFields' => array('SERVICE_ID', 'XML_ID', 'LOCATION_ID'),
		'parameters' => array(
			'mtu' => $mtu
		)
	));

	if($this->getStep() == 0)
	{
		// set initial values
		$this->data['current'] = array(
			'fIndex' => 0,
			'bytesRead' => 0, // current file bytes read
			'linesRead' => 0
		);

		$this->hitData['HANDLES']['LOCATION']->resetAutoIncrementFromIndex(); // synchronize sequences, etc...

		// check if we are empty
		$this->data['TABLE_WERE_EMPTY'] = LocationLocationTable::getCountByFilter() == 0;

		$this->buildStaticLocationIndex();
	}

	while($this->checkQuota())
	{
		$block = $this->readBlockFromCurrentFile2();
		$this->importBlock($block);

		// clean memory
		$this->manageExistedLocationIndex(array($this->getCurrentGid()));

		// or the current file is completely exhausted
		if($this->checkFileCompletelyRead())
		{
			//$this->logMessage('Lines read: '.$this->data['current']['linesRead']);

			// charge next file
			unset($this->hitData['csv']);
			$this->data['current']['fIndex']++; // next file to go
			$this->data['current']['bytesRead'] = 0; // read counter from the beginning
			$this->data['current']['linesRead'] = 0;
			$this->data['current']['legacy'] = array(); // drop legacy data of the file, if were any. bye-bye

			// may be that is all?
			if($this->checkAllFilesRead())
			{
				unset($this->data['existedlocs']); // uff, remove that huge array at last

				$this->nextStage();
				break;
			}
		}

		$this->nextStep();
	}

	$this->hitData['HANDLES']['LOCATION']->flush();
	$this->hitData['HANDLES']['NAME']->flush();
	$this->hitData['HANDLES']['EXTERNAL']->flush();

	$this->logMessage('Inserted, go next: '.$this->getHitTimeString());

	$this->logMemoryUsage();
}