- Модуль: translate
- Путь к файлу: ~/bitrix/modules/translate/lib/controller/export/exportfilelist.php
- Класс: BitrixTranslateControllerExportExportFileList
- Вызов: ExportFileList::runExporting
private function runExporting(array $params): array
{
$path = rtrim($params['path'], '/');
$subPath = trim($params['subPath'], '/');
$csvFile = new TranslateIOCsvFile($this->exportFilePath);
$this->configureExportCsvFile($csvFile);
$csvFile->openWrite( MainIOFileStreamOpenMode::APPEND);
if ($this->appendSamples)
{
$samplesFile = new TranslateIOCsvFile($this->samplesFilePath);
$this->configureExportCsvFile($samplesFile);
$samplesFile->openWrite( MainIOFileStreamOpenMode::APPEND);
}
$pathFilter = [];
$pathFilter[] = [
'LOGIC' => 'OR',
'=PATH' => $path,
'=%PATH' => $path.'/%',
];
if (!empty($this->seekPathLangId))
{
$pathFilter['>ID'] = $this->seekPathLangId;
}
$currentLangId = Loc::getCurrentLang();
$cachePathLangRes = IndexInternalsPathLangTable::getList([
'filter' => $pathFilter,
'order' => ['ID' => 'ASC'],
'select' => ['ID', 'PATH'],
]);
$processedItemCount = 0;
while ($pathLang = $cachePathLangRes->fetch())
{
$lookThroughPath = $pathLang['PATH']. '/#LANG_ID#';
if (!empty($subPath))
{
$lookThroughPath .= '/'. $subPath;
}
foreach ($this->lookThroughLangFolder($lookThroughPath) as $filePaths)
{
foreach ($filePaths as $langFilePath => $fullPaths)
{
if (!empty($this->seekLangFilePath))
{
if ($langFilePath == $this->seekLangFilePath)
{
$this->seekLangFilePath = '';
}
else
{
continue;
}
}
$rows = $this->mergeLangFiles($langFilePath, $fullPaths, $this->collectUntranslated);
foreach ($rows as $code => $row)
{
if (!empty($this->seekPhraseCode))
{
if ($code == $this->seekPhraseCode)
{
$this->seekPhraseCode = '';
}
continue;
}
$csvFile->put(array_values($row));
if (
$this->appendSamples
&& !empty($row[$currentLangId])
&& mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
)
{
$samples = $this->findSamples(
$row[$currentLangId],
$currentLangId,
$langFilePath,
$this->samplesCount,
$this->samplesRestriction
);
foreach ($samples as $sample)
{
$samplesFile->put(array_values($sample));
$this->exportedSamplesCount ++;
}
}
$this->exportedPhraseCount ++;
if ($this->instanceTimer()->hasTimeLimitReached())
{
$this->seekPhraseCode = $code;
}
else
{
$this->seekPhraseCode = '';
}
}
if ($this->instanceTimer()->hasTimeLimitReached())
{
$this->seekLangFilePath = $langFilePath;
break;
}
else
{
$this->seekLangFilePath = '';
}
}
}
$processedItemCount ++;
if ($this->instanceTimer()->hasTimeLimitReached())
{
$this->seekPathLangId = (int)$pathLang['ID'];
break;
}
}
$this->exportFileSize = $csvFile->getSize();
$csvFile->close();
if ($this->appendSamples)
{
$this->samplesFileSize = $samplesFile->getSize();
$samplesFile->close();
}
$this->processedItems += $processedItemCount;
if ($this->instanceTimer()->hasTimeLimitReached() !== true)
{
$this->declareAccomplishment();
$this->clearProgressParameters();
}
$result = [
'PROCESSED_ITEMS' => $this->processedItems,
'TOTAL_ITEMS' => $this->totalItems,
'TOTAL_PHRASES' => $this->exportedPhraseCount,
'TOTAL_SAMPLES' => $this->exportedSamplesCount,
];
if ($csvFile->hasErrors())
{
$errors = $csvFile->getErrors();
foreach ($errors as $err)
{
if ($err->getCode() == TranslateIOCsvFile::ERROR_32K_FIELD_LENGTH)
{
$result['WARNING'] = Loc::getMessage('TR_EXPORT_ERROR_32K_LENGTH');
}
else
{
$this->addError($err);
}
}
}
return $result;
}