• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/file.php
  • Класс: BitrixTranslateFile
  • Вызов: File::backup
public function backup(): bool
{
	if (!$this->isExists())
	{
		return true;
	}

	$langId = $this->getLangId();

	$fullPath = $langFile = $this->getPhysicalPath();

	if (MainLocalizationTranslation::useTranslationRepository() && in_array($langId, TranslateConfig::getTranslationRepositoryLanguages()))
	{
		if (mb_strpos($langFile, MainLocalizationTranslation::getTranslationRepositoryPath()) === 0)
		{
			$langFile = str_replace(
				MainLocalizationTranslation::getTranslationRepositoryPath(). '/',
				'',
				$langFile
			);
		}
	}
	if (MainLocalizationTranslation::getDeveloperRepositoryPath() !== null)
	{
		if (mb_strpos($langFile, MainLocalizationTranslation::getDeveloperRepositoryPath()) === 0)
		{
			$langFile = str_replace(
				MainLocalizationTranslation::getDeveloperRepositoryPath(). '/',
				'',
				$langFile
			);
		}
	}
	if (mb_strpos($langFile, MainApplication::getDocumentRoot()) === 0)
	{
		$langFile = str_replace(
			MainApplication::getDocumentRoot(). '/',
			'',
			$langFile
		);
	}

	$backupFolder = TranslateConfig::getBackupFolder(). '/'. dirname($langFile). '/';
	if (!TranslateIOPath::checkCreatePath($backupFolder))
	{
		$this->addError(new MainError("Couldn't create backup path '{$backupFolder}'"));
		return false;
	}

	$sourceFilename = basename($langFile);
	$prefix = date('YmdHi');
	$endpointBackupFilename = $prefix. '_'. $sourceFilename;
	if (file_exists($backupFolder. $endpointBackupFilename))
	{
		$i = 1;
		while (file_exists($backupFolder. '/'. $endpointBackupFilename))
		{
			$i ++;
			$endpointBackupFilename = $prefix. '_'. $i. '_'. $sourceFilename;
		}
	}

	$isSuccessfull = (bool) @copy($fullPath, $backupFolder. '/'. $endpointBackupFilename);
	@chmod($backupFolder. '/'. $endpointBackupFilename, BX_FILE_PERMISSIONS);

	if (!$isSuccessfull)
	{
		$this->addError(new MainError("Couldn't backup file '{$fullPath}'"));
	}

	return $isSuccessfull;
}