1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
exportfilelist.php
См. документацию.
1<?php
2namespace Bitrix\Translate\Controller\Export;
3
4use Bitrix\Main;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Translate;
7use Bitrix\Translate\Index;
8
13 extends ExportAction
15{
18
19 private int $seekPathLangId = 0;
20
21 private string $seekLangFilePath = '';
22 private string $seekPhraseCode = '';
23
32 {
33 $this->keepField(['seekPathLangId', 'seekLangFilePath', 'seekPhraseCode']);
34
35 Loc::loadLanguageFile(__DIR__ . '/exportaction.php');
36
37 parent::__construct($name, $controller, $config);
38 }
39
40
49 public function run(string $path = '', bool $runBefore = false): array
50 {
51 if (empty($path))
52 {
54 }
55
56 // part of the path after /lang/
57 $subPath = '';
58 if (\preg_match("#(.+/lang)(/?\w*)#", $path, $matches))
59 {
60 if (\preg_match("#(.+/lang/[^/]+/?)(.*)$#", $path, $subMatches))
61 {
62 $subPath = $subMatches[2];
63 }
64 $path = $matches[1];
65 }
66 unset($matches, $subMatches);
67
68
69 if ($runBefore)
70 {
71 $this->onBeforeRun();
72 }
73
74 if ($this->isNewProcess)
75 {
76 $this->totalItems = (int)Index\Internals\PathLangTable::getCount(['=%PATH' => $path.'%']);
77 $this->processedItems = 0;
78
79 if ($this->totalItems > 0)
80 {
81 $this->exportFileName = $this->generateExportFileName($path, $this->languages);
82 $csvFile = $this->createExportTempFile($this->exportFileName);
83 $this->exportFilePath = $csvFile->getPhysicalPath();
84 $this->exportFileSize = $csvFile->getSize();
85 }
86 if ($this->appendSamples)
87 {
88 $this->samplesFileName = $this->generateExportFileName($path.'-samples', $this->languages);
89 $sampleFile = $this->createExportTempFile($this->samplesFileName);
90 $this->samplesFilePath = $sampleFile->getPhysicalPath();
91 $this->samplesFileSize = $sampleFile->getSize();
92 }
93
95
96 return [
98 'PROCESSED_ITEMS' => 0,
99 'TOTAL_ITEMS' => $this->totalItems,
100 'TOTAL_PHRASES' => $this->exportedPhraseCount,
101 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
102 ];
103 }
104
105 return $this->performStep('runExporting', ['path' => $path, 'subPath' => $subPath]);
106 }
107
115 private function runExporting(array $params): array
116 {
117 $path = \rtrim($params['path'], '/');
118 $subPath = \trim($params['subPath'], '/');
119
120 $csvFile = new Translate\IO\CsvFile($this->exportFilePath);
121 $this->configureExportCsvFile($csvFile);
122 $csvFile->openWrite( Main\IO\FileStreamOpenMode::APPEND);
123
124 if ($this->appendSamples)
125 {
126 $samplesFile = new Translate\IO\CsvFile($this->samplesFilePath);
127 $this->configureExportCsvFile($samplesFile);
128 $samplesFile->openWrite( Main\IO\FileStreamOpenMode::APPEND);
129 }
130
131 $pathFilter = [];
132 $pathFilter[] = [
133 'LOGIC' => 'OR',
134 '=PATH' => $path,
135 '=%PATH' => $path.'/%',
136 ];
137 if (!empty($this->seekPathLangId))
138 {
139 $pathFilter['>=ID'] = $this->seekPathLangId;
140 }
141
142 $currentLangId = Loc::getCurrentLang();
143
144 $cachePathLangRes = Index\Internals\PathLangTable::getList([
145 'filter' => $pathFilter,
146 'order' => ['ID' => 'ASC'],
147 'select' => ['ID', 'PATH'],
148 ]);
149 $processedItemCount = 0;
150 while ($pathLang = $cachePathLangRes->fetch())
151 {
152 $lookThroughPath = $pathLang['PATH']. '/#LANG_ID#';
153 if (!empty($subPath))
154 {
155 $lookThroughPath .= '/'. $subPath;
156 }
157 foreach ($this->lookThroughLangFolder($lookThroughPath) as $filePaths)
158 {
159 foreach ($filePaths as $langFilePath => $fullPaths)
160 {
161 if (!empty($this->seekLangFilePath))
162 {
163 if ($langFilePath == $this->seekLangFilePath)
164 {
165 $this->seekLangFilePath = '';
166 }
167 else
168 {
169 continue;
170 }
171 }
172
173 $rows = $this->mergeLangFiles($langFilePath, $fullPaths, $this->collectUntranslated);
174 foreach ($rows as $code => $row)
175 {
176 if (!empty($this->seekPhraseCode))
177 {
178 if ($code == $this->seekPhraseCode)
179 {
180 $this->seekPhraseCode = '';
181 }
182 continue;
183 }
184
185 $csvFile->put(array_values($row));
186
187 if (
188 $this->appendSamples
189 && !empty($row[$currentLangId])
190 && mb_strlen($row[$currentLangId]) < $this->maxSampleSourceLength
191 )
192 {
193 $samples = $this->findSamples(
194 $row[$currentLangId],
195 $currentLangId,
196 $langFilePath,
197 $this->samplesCount,
198 $this->samplesRestriction
199 );
200 foreach ($samples as $sample)
201 {
202 $samplesFile->put(\array_values($sample));
203 $this->exportedSamplesCount ++;
204 }
205 }
206
207 $this->exportedPhraseCount ++;
208
209 if ($this->instanceTimer()->hasTimeLimitReached())
210 {
211 $this->seekPhraseCode = $code;
212 break;
213 }
214 else
215 {
216 $this->seekPhraseCode = '';
217 }
218 }
219
220 if ($this->instanceTimer()->hasTimeLimitReached())
221 {
222 $this->seekLangFilePath = $langFilePath;
223 break;
224 }
225 else
226 {
227 $this->seekLangFilePath = '';
228 }
229 }
230 }
231
232 $processedItemCount ++;
233
234 if ($this->instanceTimer()->hasTimeLimitReached())
235 {
236 $this->seekPathLangId = (int)$pathLang['ID'];
237 break;
238 }
239 }
240
241 $this->exportFileSize = $csvFile->getSize();
242 $csvFile->close();
243
244 if ($this->appendSamples)
245 {
246 $this->samplesFileSize = $samplesFile->getSize();
247 $samplesFile->close();
248 }
249
250 $this->processedItems += $processedItemCount;
251
252 if ($this->instanceTimer()->hasTimeLimitReached() !== true)
253 {
254 $this->declareAccomplishment();
256 }
257
258 $result = [
259 'PROCESSED_ITEMS' => $this->processedItems,
260 'TOTAL_ITEMS' => $this->totalItems,
261 'TOTAL_PHRASES' => $this->exportedPhraseCount,
262 'TOTAL_SAMPLES' => $this->exportedSamplesCount,
263 ];
264
265 if ($csvFile->hasErrors())
266 {
267 $errors = $csvFile->getErrors();
268 foreach ($errors as $err)
269 {
270 if ($err->getCode() == Translate\IO\CsvFile::ERROR_32K_FIELD_LENGTH)
271 {
272 $result['WARNING'] = Loc::getMessage('TR_EXPORT_ERROR_32K_LENGTH');
273 }
274 else
275 {
276 $this->addError($err);
277 }
278 }
279 }
280
281 return $result;
282 }
283}
$path
Определения access_edit.php:21
onBeforeRun()
Определения action.php:159
$controller
Определения action.php:23
static getList(array $parameters=array())
Определения datamanager.php:431
static getDefaultPath()
Определения config.php:376
lookThroughLangFolder(string $langPath)
Определения exportaction.php:378
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)
Определения exportfilelist.php:49
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения exportfilelist.php:31
</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
$pathLang
Определения jscore.php:6
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
addError(Main\Error $error)
Определения error.php:22
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$matches
Определения index.php:22
$rows
Определения options.php:264