1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
pathlangcollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Translate\Index;
4
5use Bitrix\Main;
6use Bitrix\Main\Localization;
7use Bitrix\Translate;
8use Bitrix\Translate\Index;
9
10
16{
20 static $verbose = false;
21
23 private static $documentRoot;
24
26 private static $enabledLanguages;
27
29 private static $useTranslationRepository;
31 private static $translationRepositoryLanguages;
33 private static $translationEnabledLanguages;
35 private static $translationRepositoryRoot;
36
42 private static function configure()
43 {
44 self::$documentRoot = \rtrim(Translate\IO\Path::tidy(Main\Application::getDocumentRoot()), '/');
45
46 self::$enabledLanguages = Translate\Config::getEnabledLanguages();
47
48 self::$useTranslationRepository = Localization\Translation::useTranslationRepository();
49 if (self::$useTranslationRepository)
50 {
51 self::$translationRepositoryLanguages = Translate\Config::getTranslationRepositoryLanguages();
52 self::$translationRepositoryRoot = \rtrim(Localization\Translation::getTranslationRepositoryPath(), '/');
53
54 // only active languages
55 self::$translationEnabledLanguages = \array_intersect(self::$translationRepositoryLanguages, self::$enabledLanguages);
56 }
57 }
58
66 public function countItemsToProcess(?Translate\Filter $filter = null): int
67 {
68 $relPath = isset($filter, $filter->path) ? $filter->path : '';
69
70 if (!empty($relPath))
71 {
72 $relPath = '/'. \trim($relPath, '/');
73 $totalItems = (int)Index\Internals\PathLangTable::getCount(['=%PATH' => $relPath .'%']);
74 }
75 else
76 {
77 $totalItems = (int)Index\Internals\PathLangTable::getCount();
78 }
79
80 return $totalItems;
81 }
82
92 public function collect(?Translate\Filter $filter = null, ?Translate\Controller\ITimeLimit $timer = null, ?Translate\Filter $seek = null): int
93 {
94 self::configure();
95
96 if (isset($filter, $filter->path))
97 {
98 $relPath = $filter->path;
99 }
100 else
101 {
103 }
104 $relPath = '/'. \trim($relPath, '/');
105
106 // If it is lang folder, do nothing
107 if (\basename($relPath) == 'lang')
108 {
110
111 return 1;
112 }
113
114 $seekAncestors = [];
115 if (isset($seek, $seek->path))
116 {
117 $seekAncestors = \explode('/', \trim($seek->path, '/'));
118 $seek->lookForSeek = true;
119 }
120
121 $checkLanguages = [];
122 if (self::$useTranslationRepository)
123 {
124 $checkLanguages = self::$translationEnabledLanguages;
125 if (isset($filter, $filter->langId))
126 {
127 $checkLanguages = \array_intersect($filter->langId, $checkLanguages);
128 }
129 }
130
131 $pathDepthLevel = \count(\explode('/', \trim($relPath, '/'))) - 1;
132
133 $cache = [];
134 $processedItemCount = 0;
135
142 $lookForLangDirectory = function ($startRoot, $relPath, $depthLevel, $isTop = false)
143 use (&$lookForLangDirectory, &$cache, $checkLanguages, &$seek, $seekAncestors, &$processedItemCount)
144 {
145 $childrenList = [];
146
147 $mergeChildrenList = function($childrenList0, $langId = '') use (&$childrenList)
148 {
149 foreach ($childrenList0 as $childPath)
150 {
151 $name = \basename($childPath);
152 if (\in_array($name, Translate\IGNORE_FS_NAMES))
153 {
154 continue;
155 }
156 if (isset($childrenList[$name]))
157 {
158 continue;
159 }
160
161 if (self::$useTranslationRepository && $langId != '')
162 {
163 $childPath = \str_replace(
164 self::$translationRepositoryRoot. '/'. $langId,
165 self::$documentRoot. '/bitrix/modules',
166 $childPath
167 );
168 }
169
170 $childrenList[$name] = $childPath;
171 }
172 };
173
174 $mergeChildrenList(Translate\IO\FileSystemHelper::getFolderList($startRoot. $relPath));
175
176 if (self::$useTranslationRepository)
177 {
178 foreach ($checkLanguages as $langId)
179 {
180 $path1 = Localization\Translation::convertLangPath($startRoot. $relPath, $langId);
181 if ($path1 != $startRoot)
182 {
183 $mergeChildrenList(Translate\IO\FileSystemHelper::getFolderList($path1), $langId);
184 }
185 }
186 }
187
188 if (!empty($childrenList))
189 {
190 $ignoreDev = \implode('|', Translate\IGNORE_MODULE_NAMES);
191 foreach ($childrenList as $childPath)
192 {
193 $name = \basename($childPath);
194 $relChildPath = \str_replace($startRoot, '', $childPath);
195
196 if (\in_array($name, Translate\IGNORE_FS_NAMES))
197 {
198 continue;
199 }
200 if (\in_array($relChildPath, Translate\IGNORE_BX_NAMES))
201 {
202 continue;
203 }
204 // /bitrix/modules/[smth]/dev/
205 if (\preg_match("#/bitrix/modules/[^/]+/({$ignoreDev})$#", $relChildPath))
206 {
207 continue;
208 }
209
210 $isLang = ($name == 'lang');
211
212 if ($seek !== null && $seek->lookForSeek === true)
213 {
214 if ($seekAncestors[$depthLevel + 1] == $name)
215 {
216 if ($relChildPath == $seek->path)
217 {
218 if (self::$verbose)
219 {
220 echo "Seek folder: {$relChildPath}\n";
221 }
222 $seek->lookForSeek = false;// found
223 continue;
224 }
225
226 if (!$isLang)
227 {
228 foreach ($lookForLangDirectory($startRoot, $relChildPath, $depthLevel + 1) as $subChildPath)// go deeper
229 {
230 }
231 }
232 }
233
234 continue;
235 }
236
237 if ($isLang)
238 {
239 $cache[] = [
240 'PATH' => $relChildPath,
241 ];
242
243 if (\count($cache) >= 50)
244 {
245 Index\Internals\PathLangTable::bulkAdd($cache);
246 $processedItemCount += \count($cache);
247 $cache = [];
248 }
249 }
250 else
251 {
252 foreach ($lookForLangDirectory($startRoot, $relChildPath, $depthLevel + 1) as $subChildPath)// go deeper
253 {
254 yield $subChildPath;
255 }
256 }
257
258 if ($isLang)
259 {
260 yield $relChildPath;
261 }
262 }
263 }
264
265 if ($isTop && \count($cache) > 0)
266 {
267 Index\Internals\PathLangTable::bulkAdd($cache);
268 $processedItemCount += \count($cache);
269 $cache = [];
270 }
271 };
272
273 foreach ($lookForLangDirectory(self::$documentRoot, $relPath, $pathDepthLevel, true) as $langPath)
274 {
275 if (self::$verbose)
276 {
277 if (!$langPath instanceof \Generator)
278 {
279 echo "Lang folder: {$langPath}\n";
280 }
281 }
282 if ($timer !== null)
283 {
284 if ($timer->hasTimeLimitReached())
285 {
286 $seek->nextPath = $langPath;
287 break;
288 }
289 }
290 // check user abortion
291 if (\connection_status() !== \CONNECTION_NORMAL)
292 {
293 throw new Main\SystemException('Process has been broken course user aborted connection.');
294 }
295 }
296
297 if (\count($cache) > 0)
298 {
299 Index\Internals\PathLangTable::bulkAdd($cache);
300 $processedItemCount += \count($cache);
301 }
302
303 return $processedItemCount;
304 }
305
313 public function purge(?Translate\Filter $filter = null): self
314 {
316
317 return $this;
318 }
319}
static useTranslationRepository()
Определения translation.php:173
static getTranslationRepositoryPath()
Определения translation.php:193
static convertLangPath($langFile, $language)
Определения translation.php:267
static add(array $data)
Определения datamanager.php:877
static getEnabledLanguages()
Определения config.php:211
static getDefaultPath()
Определения config.php:376
static getTranslationRepositoryLanguages()
Определения config.php:316
static purge(?Translate\Filter $filter=null)
Определения pathlang.php:73
countItemsToProcess(?Translate\Filter $filter=null)
Определения pathlangcollection.php:66
collect(?Translate\Filter $filter=null, ?Translate\Controller\ITimeLimit $timer=null, ?Translate\Filter $seek=null)
Определения pathlangcollection.php:92
purge(?Translate\Filter $filter=null)
Определения pathlangcollection.php:313
$relPath
Определения component_props2.php:52
$filter
Определения iblock_catalog_list.php:54
$name
Определения menu_edit.php:35
Определения directory.php:3
Определения autoload.php:3
const IGNORE_BX_NAMES
Определения autoload.php:56
const IGNORE_MODULE_NAMES
Определения autoload.php:81
const IGNORE_FS_NAMES
Определения autoload.php:41
</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