• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/controller/import/importcsv.php
  • Класс: BitrixTranslateControllerImportImportCsv
  • Вызов: ImportCsv::run
public function run($runBefore = false)
{
	if ($runBefore)
	{
		$this->onBeforeRun();
	}

	$this->csvFile = new TranslateIOCsvFile($this->csvFilePath);

	$this->csvFile
		->setFieldsType(TranslateIOCsvFile::FIELDS_TYPE_WITH_DELIMITER)
		->setFirstHeader(false)
	;

	if (!$this->csvFile->openLoad())
	{
		$this->addError(new MainError(Loc::getMessage('TR_IMPORT_EMPTY_FILE_ERROR')));

		return [
			'STATUS' => TranslateControllerSTATUS_COMPLETED
		];
	}
	if (!$this->verifyCsvFile())
	{
		return [
			'STATUS' => TranslateControllerSTATUS_COMPLETED
		];
	}

	if ($this->csvFile->hasUtf8Bom())
	{
		$this->encodingIn = 'utf-8';
	}

	if ($this->isNewProcess)
	{
		$this->clearProgressParameters();

		$this->totalItems = 0;
		while ($csvRow = $this->csvFile->fetch())
		{
			$this->totalItems ++;
		}

		$this->processedItems = 0;
		$this->seekLine = 0;

		$this->saveProgressParameters();

		return [
			'STATUS' => TranslateControllerSTATUS_PROGRESS,
			'PROCESSED_ITEMS' => 0,
			'TOTAL_ITEMS' => $this->totalItems,
		];
	}
	else
	{
		$progressParams = $this->getProgressParameters();

		if (isset($progressParams['totalItems']))
		{
			$this->totalItems = $progressParams['totalItems'];
		}
		if (isset($progressParams['seekLine']))
		{
			$this->seekLine = $progressParams['seekLine'];
		}
		if (isset($progressParams['importedPhrasesCount']))
		{
			$this->importedPhraseCount = $progressParams['importedPhrasesCount'];
		}
	}

	return $this->performStep('runImporting');
}