- Модуль: translate
- Путь к файлу: ~/bitrix/modules/translate/lib/controller/asset/applypublic.php
- Класс: BitrixTranslateControllerAssetApplyPublic
- Вызов: ApplyPublic::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);
}
}
$sourceDirectory = new TranslateIODirectory($this->sourceFolderPath);
foreach ($sourceDirectory->getChildren() as $entry)
{
$moduleName = $entry->getName();
if (in_array($moduleName, TranslateIGNORE_FS_NAMES) || !$entry->isDirectory())
{
continue;
}
if (!empty($this->seekModule))
{
if ($this->seekModule !== $moduleName)
{
continue;
}
$this->seekModule = null;
}
foreach (self::SOURCE_FOLDERS as $type => $typeSourcePath)
{
if (!empty($this->seekType))
{
if ($this->seekType !== $type)
{
continue;
}
$this->seekType = null;
}
$sourceFolder = new MainIODirectory($entry->getPhysicalPath(). $typeSourcePath);
if ($sourceFolder->isExists())
{
$targetFolderPath = str_replace('#BX_ROOT#', self::$documentRoot. ''. BX_ROOT, self::TARGET_FOLDERS[$type]);
foreach ($this->lookThroughTmpFolder($sourceFolder->getPhysicalPath()) as $filePaths)
{
foreach ($filePaths as $langFilePath => $sourceFullPath)
{
$targetPath =
$targetFolderPath .'/'.
str_replace($moduleName. $typeSourcePath .'/', '', dirname($langFilePath));
$targetFolder = new MainIODirectory($targetPath);
if (!$targetFolder->isExists())
{
$targetFolder->create();
}
$moduleSourcePath = self::$documentRoot. ''. BX_ROOT. '/modules/'. $langFilePath;
$source = new MainIOFile($moduleSourcePath);
if (!$source->isExists())
{
continue;
}
$target = new MainIOFile($targetFolder->getPhysicalPath(). '/'. basename($langFilePath));
if ($target->isExists())
{
$target->markWritable();
}
try
{
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()));
}
}
}
if ($this->instanceTimer()->hasTimeLimitReached())
{
$this->seekPath = $sourceFullPath;
$this->seekModule = $moduleName;
$this->seekType = $type;
break 2;
}
}
// check user abortion
if (connection_status() !== CONNECTION_NORMAL)
{
throw new MainSystemException('Process has been broken course user aborted connection.');
}
}
}
$this->processedItems += $processedItemCount;
$result = [
'PROCESSED_ITEMS' => $this->processedItems,
'TOTAL_ITEMS' => $this->totalItems,
];
if ($this->instanceTimer()->hasTimeLimitReached() !== true)
{
$this->declareAccomplishment();
$this->clearProgressParameters();
$result['SUMMARY'] = Loc::getMessage('TR_LANGUAGE_DOWNLOADED');
}
return $result;
}