• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/controller/asset/apply.php
  • Класс: BitrixTranslateControllerAssetApply
  • Вызов: Apply::runApplying
private function runApplying(): array
{
	$processedItemCount = 0;

	if (!empty($this->seekPath))
	{
		$this->seekAncestors = [];
		$arr = explode('/', str_replace($this->sourceFolderPath, '', $this->seekPath));
		array_pop($arr);//last file
		$parts = [];
		foreach ($arr as $part)
		{
			$parts[] = $part;
			$this->seekAncestors[] = $this->sourceFolderPath. implode('/', $parts);
		}
	}

	foreach ($this->lookThroughTmpFolder($this->sourceFolderPath) as $filePaths)
	{
		foreach ($filePaths as $langFilePath => $fullPath)
		{
			$targetFolder = new MainIODirectory($this->targetFolderPath. dirname($langFilePath));
			if (!$targetFolder->isExists())
			{
				$targetFolder->create();
			}

			$source = new MainIOFile($fullPath);
			$target = new MainIOFile($targetFolder->getPhysicalPath(). '/'. basename($langFilePath));
			if ($target->isExists())
			{
				$target->markWritable();
			}

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

					$content = MainTextEncoding::convertEncoding($content, $this->encodingIn, $this->encodingOut);
					$target->putContents($content);
				}
				else
				{
					if (function_exists('error_clear_last'))
					{
						error_clear_last();
					}
					if (copy($source->getPhysicalPath(), $target->getPhysicalPath()) !== true)
					{
						$error = error_get_last();
						$this->addError(new MainError($error['message'], $error['type']));
						continue;
					}
				}

				$processedItemCount ++;
			}
			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.');
			}
		}

		if ($this->instanceTimer()->hasTimeLimitReached())
		{
			$this->seekPath = $fullPath;
			break;
		}
	}

	$this->processedItems += $processedItemCount;

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

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

		$updatePublic = $this->controller->getRequest()->get('updatePublic');
		if ($updatePublic === 'Y')
		{
			// we have to continue process in next action
			$this->processToken = null;
		}
		else
		{
			$this->clearProgressParameters();
		}

		$result['SUMMARY'] = Loc::getMessage('TR_LANGUAGE_DOWNLOADED');
	}

	return $result;
}