16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
19 private int $seekPathId = 0;
20 private string $seekPhraseCode =
'';
31 $this->
keepField([
'seekPathId',
'seekPhraseCode']);
47 public function run(
string $path =
'',
bool $runBefore =
false): array
51 $path = Translate\Config::getDefaultPath();
59 if ($this->isNewProcess)
61 $this->totalItems = (int)Index\FileIndexSearch::getCount($this->processFilter($path));
62 $this->processedItems = 0;
64 if ($this->totalItems > 0)
67 $csvFile = $this->createExportTempFile($this->exportFileName);
68 $this->exportFilePath = $csvFile->getPhysicalPath();
69 $this->exportFileSize = $csvFile->getSize();
71 if ($this->appendSamples)
74 $sampleFile = $this->createExportTempFile($this->samplesFileName);
75 $this->samplesFilePath = $sampleFile->getPhysicalPath();
76 $this->samplesFileSize = $sampleFile->getSize();
82 'STATUS' => ($this->totalItems > 0 ? Translate\Controller\STATUS_PROGRESS : Translate\Controller\STATUS_COMPLETED),
83 'PROCESSED_ITEMS' => 0,
84 'TOTAL_ITEMS' => $this->totalItems,
85 'TOTAL_PHRASES' => $this->exportedPhraseCount,
86 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
90 return $this->
performStep(
'runExporting', [
'path' => $path]);
101 private function runExporting(array $params): array
103 $path = \rtrim($params[
'path'],
'/');
109 if ($this->appendSamples)
116 $pathFilter = $this->processFilter($path);
117 if (!empty($this->seekPathId))
119 $pathFilter[
'>PATH_ID'] = $this->seekPathId;
122 $select = [
'PATH_ID',
'PATH'];
124 foreach ($this->languages as $langId)
126 $select[] = \mb_strtoupper($langId).
"_LANG";
128 if (!\in_array($this->filter[
'LANGUAGE_ID'], $this->languages))
130 $select[] = \mb_strtoupper($this->filter[
'LANGUAGE_ID']).
"_LANG";
136 $pathInxRes = Index\FileIndexSearch::getList([
137 'filter' => $pathFilter,
138 'order' => [
'PATH_ID' =>
'ASC'],
142 $processedItemCount = 0;
143 while ($pathInx = $pathInxRes->fetch())
145 $fullPaths = $this->
getFullPath($pathInx[
'PATH_ID']);
147 $rows = $this->
mergeLangFiles($pathInx[
'PATH'], $fullPaths, $this->collectUntranslated);
148 foreach ($rows as $code => $row)
150 if (!empty($this->seekPhraseCode))
152 if ($code == $this->seekPhraseCode)
154 $this->seekPhraseCode =
'';
159 $csvFile->put(array_values($row));
163 && !empty($row[$currentLangId])
164 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
167 $samples = $this->findSamples(
168 $row[$currentLangId],
170 (
int)$pathInx[
'PATH_ID'],
172 $this->samplesRestriction
174 foreach ($samples as $sample)
176 $samplesFile->put(\array_values($sample));
177 $this->exportedSamplesCount ++;
181 $this->exportedPhraseCount ++;
185 $this->seekPhraseCode = $code;
190 $this->seekPhraseCode =
'';
194 $processedItemCount ++;
198 $this->seekPathId = (int)$pathInx[
'PATH_ID'];
203 $this->exportFileSize = $csvFile->getSize();
206 if ($this->appendSamples)
208 $this->samplesFileSize = $samplesFile->getSize();
209 $samplesFile->close();
212 $this->processedItems += $processedItemCount;
227 if ($csvFile->hasErrors())
229 $errors = $csvFile->getErrors();
230 foreach ($errors as $err)
232 if ($err->getCode() == Translate\
IO\CsvFile::ERROR_32K_FIELD_LENGTH)
253 private function processFilter(
string $path): array
257 if ($this->filter->count() > 0)
259 foreach ($this->filter as $key => $value)
261 if (!\in_array($key, [
'FILTER_ID',
'PRESET_ID',
'FILTER_APPLIED',
'FIND',
'tabId']))
263 $filterOut[$key] = $value;
268 $filterOut[
'PATH'] = Translate\IO\Path::replaceLangId($path,
'#LANG_ID#');
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)