• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/controller/asset/collect.php
  • Класс: BitrixTranslateControllerAssetCollect
  • Вызов: Collect::runCollecting
private function runCollecting(array $params = [])
{
	if ($this->convertEncoding)
	{
		$sourceEncoding = MainLocalizationTranslation::getSourceEncoding($this->languageId);
	}

	if (isset($params['path']))
	{
		$path = $params['path'];
	}
	else
	{
		$path = Grabber::START_PATH;
	}

	$pathFilter = [
		'=%PATH' => $path.'%'
	];
	if (!empty($this->seekPathLangId))
	{
		$pathFilter['>ID'] = $this->seekPathLangId;
	}

	$cachePathLangRes = IndexInternalsPathLangTable::getList([
		'filter' => $pathFilter,
		'order' => ['ID' => 'ASC'],
		'select' => ['ID', 'PATH'],
	]);
	$processedItemCount = 0;
	while ($pathLang = $cachePathLangRes->fetch())
	{
		foreach ($this->lookThroughLangFolder($pathLang['PATH']. '/'.$this->languageId) as $filePaths)
		{
			foreach ($filePaths as $langFilePath => $fullPath)
			{
				$targetFolder = new MainIODirectory($this->tmpFolderPath. dirname($langFilePath));
				if (!$targetFolder->isExists())
				{
					$targetFolder->create();
				}

				$source = new MainIOFile($fullPath);
				$target = new MainIOFile($targetFolder->getPhysicalPath(). '/'. basename($langFilePath));

				try
				{
					$content = $source->getContents();
					$content = str_replace(["rn", "r"], ["n", "n"], $content);

					if ($this->convertEncoding)
					{
						$content = MainTextEncoding::convertEncoding($content, $sourceEncoding, $this->encoding);
					}

					$target->putContents($content);
					$this->totalFileCount ++;
				}
				catch (MainIOIoException $exception)
				{
					$this->addError(new MainError($exception->getMessage()));
				}

				// check user abortion
				if (connection_status() !== CONNECTION_NORMAL)
				{
					throw new MainSystemException('Process has been broken course user aborted connection.');
				}
			}
		}

		$processedItemCount ++;

		if ($this->instanceTimer()->hasTimeLimitReached())
		{
			$this->seekPathLangId = (int)$pathLang['ID'];
			break;
		}
	}

	$this->processedItems += $processedItemCount;

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

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

		// we have to continue process in next action
		$this->processToken = null;
		$this->seekPathLangId = null;
		$this->saveProgressParameters();

		$messagePlaceholders = [
			'#TOTAL_FILES#' => $this->totalFileCount,
			'#LANG#' => mb_strtoupper($this->languageId),
			'#PATH#' => '~tmp~',
		];
		$result['SUMMARY'] = Loc::getMessage('TR_LANGUAGE_COLLECTED_FOLDER', $messagePlaceholders);
	}

	return $result;
}