16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
19 private string $pathList =
'';
21 private int $seekPathId = 0;
32 $this->
keepField([
'pathList',
'seekPathId']);
48 public function run(
string $path =
'',
bool $runBefore =
false): array
52 $path = Translate\Config::getDefaultPath();
60 if ($this->isNewProcess)
62 $pathList = $this->controller->getRequest()->get(
'pathList');
63 if (!empty($pathList))
65 $this->pathList = $pathList;
69 $this->processedItems = 0;
71 if ($this->totalItems > 0)
74 $csvFile = $this->createExportTempFile($this->exportFileName);
75 $this->exportFilePath = $csvFile->getPhysicalPath();
76 $this->exportFileSize = $csvFile->getSize();
78 if ($this->appendSamples)
81 $sampleFile = $this->createExportTempFile($this->samplesFileName);
82 $this->samplesFilePath = $sampleFile->getPhysicalPath();
83 $this->samplesFileSize = $sampleFile->getSize();
89 'STATUS' => ($this->totalItems > 0 ? Translate\Controller\STATUS_PROGRESS : Translate\Controller\STATUS_COMPLETED),
90 'PROCESSED_ITEMS' => 0,
91 'TOTAL_ITEMS' => $this->totalItems,
92 'TOTAL_PHRASES' => $this->exportedPhraseCount,
93 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
97 return $this->
performStep(
'runExporting', [
'path' => $path]);
108 private function runExporting(array $params): array
110 $path = \rtrim($params[
'path'],
'/');
116 if ($this->appendSamples)
123 $phraseFilter = $this->processFilter($path);
124 if (!empty($this->seekPathId))
126 $phraseFilter[
'>PATH_ID'] = $this->seekPathId;
129 $select = [
'PATH_ID',
'PHRASE_CODE',
'FILE_PATH'];
131 foreach ($this->languages as $langId)
133 $select[] = \mb_strtoupper($langId).
"_LANG";
135 if (!\in_array($this->filter[
'LANGUAGE_ID'], $this->languages))
137 $select[] = \mb_strtoupper($this->filter[
'LANGUAGE_ID']).
"_LANG";
143 $phraseInxRes = Index\PhraseIndexSearch::getList([
144 'filter' => $phraseFilter,
145 'order' => [
'PATH_ID' =>
'ASC'],
149 $processedItemCount = 0;
153 while ($phraseInx = $phraseInxRes->fetch())
157 if ($prevPathId != (
int)$phraseInx[
'PATH_ID'])
159 $this->seekPathId = $prevPathId;
164 $pathId = (int)$phraseInx[
'PATH_ID'];
165 $phraseCode = $phraseInx[
'PHRASE_CODE'];
167 if (!isset($fileInxCache[$pathId]))
171 $fileInxCache[$pathId] = $this->
mergeLangFiles($phraseInx[
'FILE_PATH'], $fullPaths, $this->collectUntranslated);
174 if (isset($fileInxCache[$pathId][$phraseCode]))
176 $row = &$fileInxCache[$pathId][$phraseCode];
177 $csvFile->put(\array_values($row));
181 && !empty($row[$currentLangId])
182 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
185 $samples = $this->findSamples(
186 $row[$currentLangId],
190 $this->samplesRestriction
192 foreach ($samples as $sample)
194 $samplesFile->put(\array_values($sample));
195 $this->exportedSamplesCount ++;
199 $this->exportedPhraseCount ++;
202 $processedItemCount ++;
204 $prevPathId = $pathId;
207 $this->exportFileSize = $csvFile->getSize();
210 if ($this->appendSamples)
212 $this->samplesFileSize = $samplesFile->getSize();
213 $samplesFile->close();
216 $this->processedItems += $processedItemCount;
240 private function processFilter(
string $path): array
244 if ($this->filter->count() > 0)
246 foreach ($this->filter as $key => $value)
248 if (!\in_array($key, [
'FILTER_ID',
'PRESET_ID',
'FILTER_APPLIED',
'FIND',
'tabId']))
250 $filterOut[$key] = $value;
255 $filterOut[
'PATH'] = Translate\IO\Path::replaceLangId($path,
'#LANG_ID#');
257 if (!empty($this->pathList))
259 $filterOut[
'INCLUDE_PATHS'] = $this->pathList;
static loadLanguageFile($file, $language=null, $normalize=true)