1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
exportfile.php
См. документацию.
1<?php
2namespace Bitrix\Translate\Controller\Export;
3
4use Bitrix\Main;
5use Bitrix\Translate;
6use Bitrix\Main\Localization\Loc;
7
12 extends ExportAction
14{
17
18 private string $seekPhraseCode = '';
19
20 private array $data = [];
21
22 private string $langFilePath = '';
23
32 {
33 Loc::loadLanguageFile(__DIR__ . '/exportaction.php');
34
35 $this->keepField('seekPhraseCode');
36
37 parent::__construct($name, $controller, $config);
38 }
39
48 public function run(string $path = '', bool $runBefore = false): array
49 {
50 if (empty($path) || !\preg_match("#(.+\/lang)(\/?\w*)#", $path, $matches))
51 {
52 $this->addError(new Main\Error(Loc::getMessage('TR_EXPORT_EMPTY_PATH_LIST')));
53
54 return [
56 ];
57 }
58 if (!Translate\IO\Path::isLangDir($path))
59 {
60 $this->addError(new Main\Error(Loc::getMessage('TR_EXPORT_FILE_NOT_LANG', ['#FILE#' => $path])));
61
62 return [
64 ];
65 }
66
67 if ($runBefore)
68 {
69 $this->onBeforeRun();
70 }
71
72 $this->langFilePath = Translate\IO\Path::replaceLangId($path, '#LANG_ID#');
73
74 $fullPaths = [];
75 foreach ($this->languages as $langId)
76 {
77 $langRelPath = Translate\IO\Path::replaceLangId($path, $langId);
78 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot . '/' . $langRelPath);
79
80 if (self::$useTranslationRepository && \in_array($langId, self::$translationRepositoryLanguages))
81 {
82 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
83 }
84
85 $fullPaths[$langId] = $langFullPath;
86 }
87
88 $this->data = $this->mergeLangFiles($this->langFilePath, $fullPaths, $this->collectUntranslated);
89
90 if ($this->isNewProcess)
91 {
92 $this->totalItems = (int)count($this->data);
93 $this->processedItems = 0;
94
95 if ($this->totalItems > 0)
96 {
97 $this->exportFileName = $this->generateExportFileName($path, $this->languages);
98 $csvFile = $this->createExportTempFile($this->exportFileName);
99 $this->exportFilePath = $csvFile->getPhysicalPath();
100 $this->exportFileSize = $csvFile->getSize();
101 }
102 if ($this->appendSamples)
103 {
104 $this->samplesFileName = $this->generateExportFileName('samples-'.$path, $this->languages);
105 $sampleFile = $this->createExportTempFile($this->samplesFileName);
106 $this->samplesFilePath = $sampleFile->getPhysicalPath();
107 $this->samplesFileSize = $sampleFile->getSize();
108 }
109
110 $this->saveProgressParameters();
111
112 return [
113 'STATUS' => $this->totalItems > 0
116 'PROCESSED_ITEMS' => 0,
117 'TOTAL_ITEMS' => $this->totalItems,
118 'TOTAL_PHRASES' => $this->exportedPhraseCount,
119 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
120 ];
121 }
122
123 return $this->performStep('runExporting', ['path' => $path]);
124 }
125
133 private function runExporting(array $params): array
134 {
135 $csvFile = new Translate\IO\CsvFile($this->exportFilePath);
136 $this->configureExportCsvFile($csvFile);
137 $csvFile->openWrite( Main\IO\FileStreamOpenMode::APPEND);
138
139 if ($this->appendSamples)
140 {
141 $samplesFile = new Translate\IO\CsvFile($this->samplesFilePath);
142 $this->configureExportCsvFile($samplesFile);
143 $samplesFile->openWrite( Main\IO\FileStreamOpenMode::APPEND);
144 }
145
146 $currentLangId = Loc::getCurrentLang();
147
148 $processedItemCount = 0;
149 foreach ($this->data as $code => $row)
150 {
151 if (!empty($this->seekPhraseCode))
152 {
153 if ($code == $this->seekPhraseCode)
154 {
155 $this->seekPhraseCode = '';
156 }
157 continue;
158 }
159
160 $csvFile->put(\array_values($row));
161
162 if (
163 $this->appendSamples
164 && !empty($row[$currentLangId])
165 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
166 )
167 {
168 $samples = $this->findSamples(
169 $row[$currentLangId],
170 $currentLangId,
171 $this->langFilePath,
172 $this->samplesCount,
173 $this->samplesRestriction
174 );
175 foreach ($samples as $sample)
176 {
177 $samplesFile->put(\array_values($sample));
178 $this->exportedSamplesCount ++;
179 }
180 }
181
182 $this->exportedPhraseCount ++;
183 $processedItemCount ++;
184
185 if ($this->instanceTimer()->hasTimeLimitReached())
186 {
187 $this->seekPhraseCode = $code;
188 break;
189 }
190 }
191
192 $this->processedItems += $processedItemCount;
193
194 $this->exportFileSize = $csvFile->getSize();
195 $csvFile->close();
196
197 if ($this->appendSamples)
198 {
199 $this->samplesFileSize = $samplesFile->getSize();
200 $samplesFile->close();
201 }
202
203 if ($this->instanceTimer()->hasTimeLimitReached() !== true)
204 {
205 $this->declareAccomplishment();
207 }
208
209 $result = [
210 'PROCESSED_ITEMS' => $this->processedItems,
211 'TOTAL_ITEMS' => $this->totalItems,
212 'TOTAL_PHRASES' => $this->exportedPhraseCount,
213 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
214 ];
215
216 if ($csvFile->hasErrors())
217 {
218 $errors = $csvFile->getErrors();
219 foreach ($errors as $err)
220 {
221 if ($err->getCode() == Translate\IO\CsvFile::ERROR_32K_FIELD_LENGTH)
222 {
223 $result['WARNING'] = Loc::getMessage('TR_EXPORT_ERROR_32K_LENGTH');
224 }
225 else
226 {
227 $this->addError($err);
228 }
229 }
230 }
231
232 return $result;
233 }
234}
$path
Определения access_edit.php:21
onBeforeRun()
Определения action.php:159
$controller
Определения action.php:23
static convertLangPath($langFile, $language)
Определения translation.php:267
configureExportCsvFile(Translate\IO\CsvFile $csvFile)
Определения exportaction.php:196
generateExportFileName(string $path, array $languages)
Определения exportaction.php:225
mergeLangFiles(string $langFilePath, array $fullLangFilePaths, bool $collectUntranslated=false, array $filterByCodeList=[])
Определения exportaction.php:270
run(string $path='', bool $runBefore=false)
Определения exportfile.php:48
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения exportfile.php:31
static replaceLangId(string $path, string $langId)
Определения path.php:98
static tidy(string $path)
Определения path.php:16
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
Определения action.php:3
Определения directory.php:3
trait ProcessParams
Определения processparams.php:12
const STATUS_COMPLETED
Определения controller.php:6
instanceTimer()
Определения stepper.php:172
int $processedItems
Определения stepper.php:20
int $totalItems
Определения stepper.php:22
performStep($action, array $params=[])
Определения stepper.php:75
declareAccomplishment(bool $flag=true)
Определения stepper.php:136
trait Stepper
Определения stepper.php:13
const STATUS_PROGRESS
Определения controller.php:7
Определения autoload.php:3
addError(Main\Error $error)
Определения error.php:22
trait Error
Определения error.php:11
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$matches
Определения index.php:22