19 private array $pathList = [];
22 private array $codeList = [];
24 private int $seekOffset = 0;
26 private int $seekPathLangId = 0;
28 private string $seekLangFilePath =
'';
29 private string $seekPhraseCode =
'';
41 $this->
keepField([
'pathList',
'codeList',
'seekOffset',
'seekPathLangId',
'seekPhraseCode',
'seekLangFilePath']);
43 Loc::loadLanguageFile(__DIR__ .
'/exportaction.php');
64 if ($this->isNewProcess)
66 $pathList = $this->controller->getRequest()->get(
'pathList');
68 $pathList = \preg_split(
"/[\r\n]+/", $pathList);
69 \array_walk($pathList,
'trim');
70 $pathList = \array_unique(\array_filter($pathList));
80 foreach ($pathList as $testPath)
86 $this->pathList[] = $testPath;
91 $this->pathList[] = $testPath;
96 $codeList = $this->controller->getRequest()->get(
'codeList');
97 if (!empty($codeList))
99 $codeList = \preg_split(
"/[\r\n]+/", $codeList);
100 \array_walk($codeList,
'trim');
101 $this->codeList = \array_unique(\array_filter($codeList));
104 $this->totalItems =
\count($this->pathList);
105 $this->processedItems = 0;
107 if ($this->totalItems > 0)
110 $csvFile = $this->createExportTempFile($this->exportFileName);
111 $this->exportFilePath = $csvFile->getPhysicalPath();
112 $this->exportFileSize = $csvFile->getSize();
114 if ($this->appendSamples)
117 $sampleFile = $this->createExportTempFile($this->samplesFileName);
118 $this->samplesFilePath = $sampleFile->getPhysicalPath();
119 $this->samplesFileSize = $sampleFile->getSize();
126 'PROCESSED_ITEMS' => 0,
127 'TOTAL_ITEMS' => $this->totalItems,
140 private function runExporting():
array
144 $csvFile->openWrite(
Main\
IO\FileStreamOpenMode::APPEND);
146 if ($this->appendSamples)
150 $samplesFile->openWrite(
Main\
IO\FileStreamOpenMode::APPEND);
153 $processedItemCount = 0;
155 $filterCodeList = $this->codeList ?: [];
157 foreach ($filterCodeList as $pathCode)
163 if (!isset($fileCodeList[$langFilePath]))
165 $fileCodeList[$langFilePath] = [];
167 $fileCodeList[$langFilePath][] =
$code;
171 $currentLangId = Loc::getCurrentLang();
173 for ($pos = ($this->seekOffset > 0 ? $this->seekOffset : 0), $total = \
count($this->pathList); $pos < $total; $pos ++)
175 $exportingPath = $this->pathList[$pos];
178 if (Translate\IO\Path::isPhpFile($exportingPath))
180 $langFilePath = Translate\IO\Path::replaceLangId($exportingPath,
'#LANG_ID#');
181 if (!empty($this->seekLangFilePath))
183 if ($langFilePath == $this->seekLangFilePath)
185 $this->seekLangFilePath =
'';
194 foreach ($this->languages as $langId)
196 $langRelPath = Translate\IO\Path::replaceLangId($exportingPath, $langId);
197 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.
'/'.$langRelPath);
199 if (self::$useTranslationRepository && \in_array($langId, self::$translationRepositoryLanguages))
201 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
204 $fullPaths[$langId] = $langFullPath;
207 $rows = $this->
mergeLangFiles($langFilePath, $fullPaths, $this->collectUntranslated, $fileCodeList[$langFilePath] ?? []);
210 if (!empty($this->seekPhraseCode))
212 if (
$code == $this->seekPhraseCode)
214 $this->seekPhraseCode =
'';
219 $csvFile->put(\array_values($row));
223 && !empty($row[$currentLangId])
224 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
227 $samples = $this->findSamples(
228 $row[$currentLangId],
232 $this->samplesRestriction
234 foreach ($samples as $sample)
236 $samplesFile->put(\array_values($sample));
237 $this->exportedSamplesCount ++;
241 $this->exportedPhraseCount ++;
245 $this->seekPhraseCode =
$code;
250 $this->seekPhraseCode =
'';
256 $this->seekLangFilePath = $langFilePath;
261 $this->seekLangFilePath =
'';
268 $exportingPath = Translate\IO\Path::tidy($exportingPath.
'/');
269 if (\preg_match(
"#(.+/lang)(/?\w*)#", $exportingPath,
$matches))
272 $lookForLangSubPath =
'';
273 if (\preg_match(
"#(.+/lang/[^/]+/?)(.*)$#", $exportingPath, $subMatches))
275 $lookForLangSubPath = $subMatches[2];
280 $lookForLangPath = $exportingPath;
281 $lookForLangSubPath =
'';
288 '=%PATH' => $lookForLangPath.
'%'
290 if ($this->seekPathLangId > 0)
292 $pathFilter[
'>=ID'] = $this->seekPathLangId;
295 $cachePathLangRes = Translate\Index\Internals\PathLangTable::getList([
296 'filter' => $pathFilter,
297 'order' => [
'ID' =>
'ASC'],
298 'select' => [
'ID',
'PATH'],
300 while (
$pathLang = $cachePathLangRes->fetch())
302 $lookThroughPath =
$pathLang[
'PATH'].
'/#LANG_ID#';
303 if (!empty($lookForLangSubPath))
305 $lookThroughPath .=
'/'. \trim($lookForLangSubPath,
'/');
309 foreach ($filePaths as $langFilePath => $fullPaths)
311 if (!empty($this->seekLangFilePath))
313 if ($langFilePath == $this->seekLangFilePath)
315 $this->seekLangFilePath =
'';
323 $rows = $this->
mergeLangFiles($langFilePath, $fullPaths, $this->collectUntranslated, $fileCodeList[$langFilePath] ?? []);
326 if (!empty($this->seekPhraseCode))
328 if (
$code == $this->seekPhraseCode)
330 $this->seekPhraseCode =
'';
335 $csvFile->put(\array_values($row));
339 && !empty($row[$currentLangId])
340 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
343 $samples = $this->findSamples(
344 $row[$currentLangId],
348 $this->samplesRestriction
350 foreach ($samples as $sample)
352 $samplesFile->put(\array_values($sample));
353 $this->exportedSamplesCount ++;
357 $this->exportedPhraseCount ++;
361 $this->seekPhraseCode =
$code;
366 $this->seekPhraseCode =
'';
372 $this->seekLangFilePath = $langFilePath;
377 $this->seekLangFilePath =
'';
384 $this->seekPathLangId = (int)
$pathLang[
'ID'];
389 $this->seekPathLangId = 0;
394 $processedItemCount ++;
396 if (isset($this->pathList[$pos + 1]))
398 $this->seekOffset = $pos + 1;
402 $this->seekOffset = 0;
413 $this->exportFileSize = $csvFile->getSize();
416 if ($this->appendSamples)
418 $this->samplesFileSize = $samplesFile->getSize();
419 $samplesFile->close();
422 $this->processedItems += $processedItemCount;
437 if ($csvFile->hasErrors())
439 $errors = $csvFile->getErrors();
442 if ($err->getCode() == Translate\IO\CsvFile::ERROR_32K_FIELD_LENGTH)
444 $result[
'WARNING'] = Loc::getMessage(
'TR_EXPORT_ERROR_32K_LENGTH');