1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
collectlangpath.php
См. документацию.
1<?php
2namespace Bitrix\Translate\Controller\Index;
3
4use Bitrix\Main;
5use Bitrix\Translate;
6use Bitrix\Translate\Index;
7
8
15{
18
20 private $seekPath = '';
21
23 private $seekOffset = 0;
24
26 private $pathList = [];
27
29 private $languages = [];
30
31
40 {
41 $this->keepField(['seekPath', 'pathList', 'seekOffset', 'languages']);
42
43 parent::__construct($name, $controller, $config);
44 }
45
53 public function run($path = '', $runBefore = false)
54 {
55 if ($runBefore)
56 {
57 $this->onBeforeRun();
58 }
59
60 if (empty($path))
61 {
63 }
64
65 $path = '/'. \trim($path, '/.\\');
66
67 // List of files and folders
68 if ($this->isNewProcess)
69 {
70 $pathList = $this->controller->getRequest()->get('pathList');
71
72 if (!empty($pathList))
73 {
74 $pathList = \preg_split("/[\r\n]+/", $pathList);
75 \array_walk($pathList, 'trim');
76 $pathList = \array_unique(\array_filter($pathList));
77 }
78
79 if (empty($pathList))
80 {
81 $pathList = [$path];
82 }
83
84 $checkIndexExists = $this->controller->getRequest()->get('checkIndexExists') === 'Y';
85
86 foreach ($pathList as $testPath)
87 {
88 if ($checkIndexExists)
89 {
90 $indexPath = Index\PathIndex::loadByPath($testPath);
91 if ($indexPath instanceof Index\PathIndex)
92 {
93 if ($indexPath->getIndexed())
94 {
95 continue;// skip indexing if index exists
96 }
97 }
98 }
99
100 if (Translate\IO\Path::isPhpFile($testPath))
101 {
102 if (!Translate\IO\Path::isLangDir($testPath))
103 {
104 continue;// skip non lang files
105 }
106 }
107
108 $this->pathList[] = $testPath;
109 }
110
111 if (empty($this->pathList))
112 {
113 return [
115 ];
116 }
117
118 $languages = $this->controller->getRequest()->get('languages');
119 if (\is_array($languages) && !\in_array('all', $languages))
120 {
121 $languages = \array_intersect($languages, Translate\Config::getEnabledLanguages());
122 if (!empty($languages))
123 {
124 $this->languages = $languages;
125 }
126 }
127
128 $this->isNewProcess = false;
129 $this->instanceTimer()->setTimeLimit(5);
130 }
131
132 return $this->performStep('runIndexing');
133 }
134
140 private function runIndexing(): array
141 {
142 $indexer = new Index\PathLangCollection();
143
144 $processedItemCount = 0;
145
146 for ($pos = ((int)$this->seekOffset > 0 ? (int)$this->seekOffset : 0), $total = \count($this->pathList); $pos < $total; $pos ++)
147 {
149
150 if (!empty($this->languages))
151 {
152 $filter->langId = $this->languages;
153 }
154
155 $testPath = $this->pathList[$pos];
156 if (\preg_match("#(.+/lang)(/?\w*)#", $testPath, $matches))
157 {
158 $filter->path = $matches[1];
159 $indexer->purge($filter);
160
161 $processedItemCount += $indexer->collect($filter);//++1
162 }
163 else
164 {
165 $filter->path = $testPath;
166
167 $seek = new Translate\Filter();
168 $seek->lookForSeek = false;
169
170 if (!empty($this->seekPath))
171 {
172 $seek->path = $this->seekPath;
173 $seek->lookForSeek = true;
174 }
175 else
176 {
177 $indexer->purge($filter);
178 }
179
180 $processedItemCount += $indexer->collect($filter, $this->instanceTimer(), $seek);
181
182 if ($this->instanceTimer()->hasTimeLimitReached())
183 {
184 if (isset($seek->nextPath))
185 {
186 $this->seekPath = $seek->nextPath;
187 }
188 break;
189 }
190
191 $this->seekPath = null;
192 }
193
194 // check user abortion
195 if (\connection_status() !== \CONNECTION_NORMAL)
196 {
197 throw new Main\SystemException('Process has been broken course user aborted connection.');
198 }
199
200 if (isset($this->pathList[$pos + 1]))
201 {
202 $this->seekOffset = $pos + 1;//next
203 }
204 else
205 {
206 $this->seekOffset = null;
207 $this->declareAccomplishment();
209 }
210
211 if ($this->instanceTimer()->hasTimeLimitReached())
212 {
213 break;
214 }
215 }
216
217 $this->processedItems += $processedItemCount;
218 $this->totalItems += $processedItemCount;
219
220 if ($this->instanceTimer()->hasTimeLimitReached() !== true)
221 {
222 $this->processedItems = $this->totalItems = (new Index\PathIndexCollection())->countItemsToProcess($filter);
223
224 $this->declareAccomplishment();
226 }
227
228 return [
229 'PROCESSED_ITEMS' => $this->processedItems,
230 'TOTAL_ITEMS' => $this->totalItems,
231 ];
232 }
233}
$path
Определения access_edit.php:21
onBeforeRun()
Определения action.php:159
$controller
Определения action.php:23
static getDefaultPath()
Определения config.php:376
run($path='', $runBefore=false)
Определения collectlangpath.php:53
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения collectlangpath.php:39
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
Определения 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
</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
$matches
Определения index.php:22