File::backup: Bitrix method

      
<?php 
//  Bitrix\Translate\File :: backup()
//  /dist/bitrix/modules/translate/lib/file.php:440

    
public function backup()
    {
        if (!
$this->isExists())
        {
            return 
true;
        }

        
$langId $this->getLangId();

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

        if (
Main\Localization\Translation::useTranslationRepository() && in_array($langIdTranslate\Config::getTranslationRepositoryLanguages()))
        {
            if (
strpos($langFileMain\Localization\Translation::getTranslationRepositoryPath()) === 0)
            {
                
$langFile str_replace(
                    
Main\Localization\Translation::getTranslationRepositoryPath(). '/',
                    
'',
                    
$langFile
                
);
            }
        }
        if (
Main\Localization\Translation::getDeveloperRepositoryPath() !== null)
        {
            if (
strpos($langFileMain\Localization\Translation::getDeveloperRepositoryPath()) === 0)
            {
                
$langFile str_replace(
                    
Main\Localization\Translation::getDeveloperRepositoryPath(). '/',
                    
'',
                    
$langFile
                
);
            }
        }
        if (
strpos($langFileMain\Application::getDocumentRoot()) === 0)
        {
            
$langFile str_replace(
                
Main\Application::getDocumentRoot(). '/',
                
'',
                
$langFile
            
);
        }

        
$backupFolder Translate\Config::getBackupFolder(). '/'dirname($langFile). '/';
        if (!
Translate\IO\Path::checkCreatePath($backupFolder))
        {
            
$this->addError(new Main\Error("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'/'$endpointBackupFilenameBX_FILE_PERMISSIONS);

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

        return 
$isSuccessfull;
    }