• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/controller/import/indexcsv.php
  • Класс: BitrixTranslateControllerImportIndexCsv
  • Вызов: IndexCsv::runIndexing
private function runIndexing(): array
{
	$fileColumn = $this->columnList['file'];

	$uniquePaths = [];

	if (!empty($this->seekPath))
	{
		$uniquePaths[$this->seekPath] = 1;
	}

	$pathIndexer = new IndexPathIndexCollection();

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

		if ($this->seekLine > 0)
		{
			if ($currentLine <= $this->seekLine)
			{
				continue;
			}
		}

		if (
			!is_array($csvRow) ||
			empty($csvRow) ||
			(count($csvRow) == 1 && ($csvRow[0] === null || $csvRow[0] === ''))
		)
		{
			continue;
		}

		$filePath = (isset($csvRow[$fileColumn]) ? $csvRow[$fileColumn] : '');
		if ($filePath == '')
		{
			continue;
		}
		if (TranslateIOPath::isLangDir($filePath, true) !== true)
		{
			continue;
		}
		$filePath = TranslateIOPath::normalize('/'.$filePath);

		if (isset($uniquePaths[$filePath]))
		{
			continue;
		}

		foreach ($this->languageList as $languageId)
		{
			$langFilePath = TranslateIOPath::replaceLangId($filePath, $languageId);

			$fullPath = self::$documentRoot. $langFilePath;
			$fullPath = MainLocalizationTranslation::convertLangPath($fullPath, $languageId);

			$langFile = new TranslateFile($fullPath);
			$langFile->setLangId($languageId);

			if (!$langFile->load())
			{
				$this->addErrors($langFile->getErrors());
				continue;
			}

			if ($langFile->getFileIndex()->getId() <= 0)
			{
				$topPath = $pathIndexer->constructAncestorsByPath($filePath);

				if ($topPath['ID'] > 0)
				{
					$fileIndex = $langFile->getFileIndex();
					$fileIndex->setPathId($topPath['ID']);
					$fileIndex->save();
				}
			}
			$langFile->updatePhraseIndex();
		}

		$uniquePaths[$filePath] = 1;
		$this->processedItems ++;

		if ($this->instanceTimer()->hasTimeLimitReached())
		{
			$this->seekLine = $currentLine;
			$this->seekPath = $filePath;
			break;
		}
	}

	$this->csvFile->close();

	if ($this->instanceTimer()->hasTimeLimitReached() !== true)
	{
		$this->declareAccomplishment();
		$this->clearProgressParameters();
	}

	return [
		'PROCESSED_ITEMS' => $this->processedItems,
		'TOTAL_ITEMS' => $this->totalItems,
	];
}