- Модуль: translate
- Путь к файлу: ~/bitrix/modules/translate/lib/controller/export/exportphrasesearch.php
- Класс: BitrixTranslateControllerExportExportPhraseSearch
- Вызов: ExportPhraseSearch::runExporting
private function runExporting(array $params): array
{
$path = rtrim($params['path'], '/');
$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);
}
$phraseFilter = $this->processFilter($path);
if (!empty($this->seekPathId))
{
$phraseFilter['>PATH_ID'] = $this->seekPathId;
}
$select = ['PATH_ID', 'PHRASE_CODE', 'FILE_PATH'];
foreach ($this->languages as $langId)
{
$select[] = mb_strtoupper($langId)."_LANG";
}
if (!in_array($this->filter['LANGUAGE_ID'], $this->languages))
{
$select[] = mb_strtoupper($this->filter['LANGUAGE_ID'])."_LANG";
}
$currentLangId = Loc::getCurrentLang();
/** @var MainORMQueryResult $cachePathRes */
$phraseInxRes = IndexPhraseIndexSearch::getList([
'filter' => $phraseFilter,
'order' => ['PATH_ID' => 'ASC'],
'select' => $select,
]);
$processedItemCount = 0;
$prevPathId = -1;
$fileInxCache = [];
while ($phraseInx = $phraseInxRes->fetch())
{
if ($this->instanceTimer()->hasTimeLimitReached())
{
if ($prevPathId != (int)$phraseInx['PATH_ID'])
{
$this->seekPathId = $prevPathId;
break;
}
}
$pathId = (int)$phraseInx['PATH_ID'];
$phraseCode = $phraseInx['PHRASE_CODE'];
if (!isset($fileInxCache[$pathId]))
{
$fullPaths = $this->getFullPath($pathId);
$fileInxCache[$pathId] = $this->mergeLangFiles($phraseInx['FILE_PATH'], $fullPaths, $this->collectUntranslated);
}
if (isset($fileInxCache[$pathId][$phraseCode]))
{
$row = &$fileInxCache[$pathId][$phraseCode];
$csvFile->put(array_values($row));
if (
$this->appendSamples
&& !empty($row[$currentLangId])
&& mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
)
{
$samples = $this->findSamples(
$row[$currentLangId],
$currentLangId,
$pathId,
$this->samplesCount,
$this->samplesRestriction
);
foreach ($samples as $sample)
{
$samplesFile->put(array_values($sample));
$this->exportedSamplesCount ++;
}
}
$this->exportedPhraseCount ++;
}
$processedItemCount ++;
$prevPathId = $pathId;
}
$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();
}
return [
'PROCESSED_ITEMS' => $this->processedItems,
'TOTAL_ITEMS' => $this->totalItems,
'TOTAL_PHRASES' => $this->exportedPhraseCount,
'TOTAL_SAMPLES' => $this->exportedSamplesCount,
];
}