19 private int $seekPathId = 0;
20 private string $seekPhraseCode =
'';
31 $this->
keepField([
'seekPathId',
'seekPhraseCode']);
33 Loc::loadLanguageFile(__DIR__ .
'/exportaction.php');
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();
83 'PROCESSED_ITEMS' => 0,
84 'TOTAL_ITEMS' => $this->totalItems,
85 'TOTAL_PHRASES' => $this->exportedPhraseCount,
86 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
107 $csvFile->openWrite(
Main\
IO\FileStreamOpenMode::APPEND);
109 if ($this->appendSamples)
113 $samplesFile->openWrite(
Main\
IO\FileStreamOpenMode::APPEND);
116 $pathFilter = $this->processFilter(
$path);
117 if (!empty($this->seekPathId))
119 $pathFilter[
'>PATH_ID'] = $this->seekPathId;
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";
133 $currentLangId = Loc::getCurrentLang();
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']);
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();
232 if ($err->getCode() == Translate\IO\CsvFile::ERROR_32K_FIELD_LENGTH)
234 $result[
'WARNING'] = Loc::getMessage(
'TR_EXPORT_ERROR_32K_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']))
268 $filterOut[
'PATH'] = Translate\IO\Path::replaceLangId(
$path,
'#LANG_ID#');