1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cleanethalon.php
См. документацию.
1<?php
3
8
15{
18
19 const SETTING_ID = 'TRANSLATE_CLEAN';
20
22 private $pathList;
23
25 private $seekOffset;
26
28 private $seekLangPath;
29
30
39 {
40 $this->keepField(['pathList', 'seekOffset', 'seekLangPath']);
41
42 parent::__construct($name, $controller, $config);
43 }
44
45
53 public function run($pathList)
54 {
55 if ($this->isNewProcess)
56 {
57 $pathList = \preg_split("/[\r\n]+/", $pathList);
58 \array_walk($pathList, 'trim');
59 $pathList = \array_unique(\array_filter($pathList));
60
61 if (empty($pathList))
62 {
63 $this->addError(new Main\Error(Loc::getMessage('TR_CLEAN_EMPTY_PATH_LIST')));
64
65 return [
67 ];
68 }
69
70 foreach ($pathList as $testPath)
71 {
72 if (Translate\IO\Path::isPhpFile($testPath))
73 {
74 if (Translate\IO\Path::isLangDir($testPath))
75 {
76 $this->pathList[] = $testPath;
77 }
78 else
79 {
80 $this->addError(new Main\Error(Loc::getMessage('TR_CLEAN_FILE_NOT_LANG', ['#FILE#' => $testPath])));
81 }
82 }
83 else
84 {
85 if (Translate\IO\Path::isLangDir($testPath))
86 {
87 $this->pathList[] = $testPath;
88 }
89 else
90 {
91 // load lang folders
92 $pathFilter = [];
93 $pathFilter[] = [
94 'LOGIC' => 'OR',
95 '=PATH' => \rtrim($testPath, '/'),
96 '=%PATH' => \rtrim($testPath, '/'). '/%'
97 ];
99 'filter' => $pathFilter,
100 'order' => ['ID' => 'ASC'],
101 'select' => ['PATH'],
102 ]);
103 while ($pathLang = $pathLangRes->fetch())
104 {
105 $this->pathList[] = $pathLang['PATH'];
106 }
107 }
108 }
109 }
110
111 $this->totalItems = \count($this->pathList);
112 $this->processedItems = 0;
113
114 if ($this->totalItems == 0)
115 {
116 return [
118 'PROCESSED_ITEMS' => 0,
119 'TOTAL_ITEMS' => 0,
120 ];
121 }
122
123 $this->saveProgressParameters();
124 $this->isNewProcess = false;
125 }
126
127 return $this->performStep('runClearing');
128 }
129
135 private function runClearing(): array
136 {
137 $processedItemCount = 0;
138 for ($pos = ((int)$this->seekOffset > 0 ? (int)$this->seekOffset : 0), $total = \count($this->pathList); $pos < $total; $pos ++)
139 {
140 $testPath = $this->pathList[$pos];
141
142 // file
143 if (Translate\IO\Path::isPhpFile($testPath))
144 {
145 $this->cleanLangFile($testPath);
146 }
147
148 // folder
149 else
150 {
151 if (\mb_substr($testPath, -5) === '/lang')
152 {
153 $testPath .= '/#LANG_ID#';
154 }
155 else
156 {
157 $testPath = Translate\IO\Path::replaceLangId($testPath, '#LANG_ID#');
158 }
159
160 foreach ($this->lookThroughLangFolder($testPath) as $filePaths)
161 {
162 foreach ($filePaths as $langFilePath => $fullPaths)
163 {
164 if (!empty($this->seekLangPath))
165 {
166 if ($this->seekLangPath == $langFilePath)
167 {
168 $this->seekLangPath = null;
169 }
170
171 continue;
172 }
173
174 $this->cleanLangFile($langFilePath);
175
176 if ($this->instanceTimer()->hasTimeLimitReached())
177 {
178 $this->seekLangPath = $langFilePath;
179 break 3;
180 }
181 }
182
183 $this->seekLangPath = null;
184 }
185 }
186
187 $processedItemCount ++;
188
189 if (isset($this->pathList[$pos + 1]))
190 {
191 $this->seekOffset = $pos + 1;//next
192 }
193 else
194 {
195 $this->seekOffset = null;
196 $this->declareAccomplishment();
198 }
199
200 if ($this->instanceTimer()->hasTimeLimitReached())
201 {
202 break;
203 }
204 }
205
206 $this->processedItems += $processedItemCount;
207
208 if ($this->instanceTimer()->hasTimeLimitReached() !== true)
209 {
210 $this->declareAccomplishment();
212 }
213
214 return [
215 'PROCESSED_ITEMS' => $this->processedItems,
216 'TOTAL_ITEMS' => $this->totalItems,
217 ];
218 }
219
220
228 private function cleanLangFile($relLangPath): void
229 {
230 $currentLang = Loc::getCurrentLang();
231 $langPath = Translate\IO\Path::replaceLangId($relLangPath, $currentLang);
232 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot. '/'. $langPath);
233 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $currentLang);
234
235 // settings
236 $langSettings = null;
237 $settingsFile = Translate\Settings::instantiateByPath($langFullPath);
238 if (($settingsFile instanceof Translate\Settings) && $settingsFile->load())
239 {
240 $langSettings = $settingsFile->getOptions($langFullPath)[Translate\Settings::OPTION_LANGUAGES];
241 }
242
243 try
244 {
245 $ethalonFile = Translate\File::instantiateByPath($langFullPath);
246 }
247 catch (Main\ArgumentException $ex)
248 {
249 return;
250 }
251 if ($ethalonFile instanceof Translate\File)
252 {
253 $ethalonFile
254 ->setLangId($currentLang)
255 ->setOperatingEncoding(Main\Localization\Translation::getSourceEncoding($currentLang));
256
257 $isEthalonExists = false;
258 if ($ethalonFile->isExists())
259 {
260 $isEthalonExists = $ethalonFile->loadTokens() || $ethalonFile->load();
261 }
262 if (!$isEthalonExists)
263 {
264 $this->deletePhraseIndex($ethalonFile);
265 }
266
267 foreach (self::$enabledLanguagesList as $langId)
268 {
269 if ($langId == $currentLang)
270 {
271 // ignore ethanol file
272 continue;
273 }
274
275 if ($langSettings && in_array($langId, $langSettings, true))
276 {
277 // do not touch obligatory language
278 continue;
279 }
280
281 $langPath = Translate\IO\Path::replaceLangId($relLangPath, $langId);
282 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.'/'.$langPath);
283 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
284
285 try
286 {
287 $langFile = Translate\File::instantiateByPath($langFullPath);
288 }
289 catch (Main\ArgumentException $ex)
290 {
291 continue;
292 }
293 if ($langFile instanceof Translate\File)
294 {
296 ->setLangId($langId)
297 ->setOperatingEncoding(Main\Localization\Translation::getSourceEncoding($langId));
298
299 if ($langFile->isExists())
300 {
301 if ($isEthalonExists && ($langFile->loadTokens() || $langFile->load()))
302 {
303 $affected = false;
304 foreach ($langFile as $code => $phrase)
305 {
306 if (!isset($ethalonFile[$code]))
307 {
308 unset($langFile[$code]);
309 $affected = true;
310 }
311 }
312 if ($affected)
313 {
316 }
317 }
318 else
319 {
322 }
323 }
324 else
325 {
326 $langFile->deletePhraseIndex();
327 }
328 }
329 }
330 }
331 }
332
333
340 {
341 return self::SETTING_ID;
342 }
343}
$controller
Определения action.php:23
static getSourceEncoding($lang)
Определения translation.php:59
static getList(array $parameters=array())
Определения datamanager.php:431
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения cleanethalon.php:38
updatePhraseIndex(Translate\File $langFile)
Определения operation.php:155
updateLangFile(Translate\File $langFile)
Определения operation.php:42
deleteLangFile(Translate\File $langFile)
Определения operation.php:104
deletePhraseIndex(Translate\File $langFile)
Определения operation.php:169
static replaceLangId(string $path, string $langId)
Определения path.php:98
$langFile
Определения .description.php:2
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$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
Определения 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