Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collectphraseindex.php
1<?php
3
7
14{
15 use Translate\Controller\Stepper;
16 use Translate\Controller\ProcessParams;
17
19 private $seekPathId = '';
20
22 private $languages = [];
23
31 public function __construct($name, Main\Engine\Controller $controller, array $config = [])
32 {
33 $this->keepField(['seekPathId', 'languages']);
34
35 parent::__construct($name, $controller, $config);
36 }
37
45 public function run($path = '')
46 {
47 if (empty($path))
48 {
49 $path = Translate\Config::getDefaultPath();
50 }
51
52 if (\preg_match("#(.+\/lang)(\/?\w*)#", $path, $matches))
53 {
54 $path = $matches[1];
55 }
56
57 $path = '/'. \trim($path, '/.\\');
58
59 if ($this->isNewProcess)
60 {
61 Index\Internals\PhraseFts::checkTables();
62
63 $languages = $this->controller->getRequest()->get('languages');
64 if (\is_array($languages) && !\in_array('all', $languages))
65 {
66 $languages = \array_intersect($languages, Translate\Config::getEnabledLanguages());
67 if (!empty($languages))
68 {
69 $this->languages = $languages;
70 }
71 }
72
73 $filter = new Translate\Filter(['path' => $path]);
74 if (!empty($this->languages))
75 {
76 $filter->langId = $this->languages;
77 }
78
79 $this->totalItems = (new Index\PhraseIndexCollection())->countItemsToProcess($filter);
80
82
83 $this->instanceTimer()->setTimeLimit(5);
84 $this->isNewProcess = false;
85 }
86 else
87 {
88 $progressParams = $this->getProgressParameters();
89
90 if (isset($progressParams['totalItems']) && (int)$progressParams['totalItems'] > 0)
91 {
92 $this->totalItems = (int)$progressParams['totalItems'];
93 $this->processedItems = (int)$progressParams['processedItems'];
94 }
95
96 if (isset($progressParams['seekPathId']))
97 {
98 $this->seekPathId = $progressParams['seekPathId'];
99 }
100 }
101
102 return $this->performStep('runIndexing', ['path' => $path]);
103 }
104
112 private function runIndexing(array $params): array
113 {
114 $path = \rtrim($params['path'], '/');
115
116 $seek = new Translate\Filter();
117 if (!empty($this->seekPathId))
118 {
119 $seek->pathId = $this->seekPathId;
120 }
121
122 $filter = new Translate\Filter(['path' => $path]);
123 if (!empty($this->languages))
124 {
125 $filter->langId = $this->languages;
126 }
127
128 $indexer = new Index\PhraseIndexCollection();
129
130 $processedItemCount = $indexer->collect($filter, $this->instanceTimer(), $seek);
131
132 $this->processedItems += $processedItemCount;
133
134 if ($this->processedItems >= $this->totalItems)
135 {
136 $this->declareAccomplishment();
138 }
139 else
140 {
141 $this->seekPathId = $seek->nextPathId;
142 }
143
144 return [
145 'PROCESSED_ITEMS' => $this->processedItems,
146 'TOTAL_ITEMS' => $this->totalItems,
147 ];
148 }
149}
__construct($name, Main\Engine\Controller $controller, array $config=[])
performStep($action, array $params=[])
Definition stepper.php:75
declareAccomplishment(bool $flag=true)
Definition stepper.php:136