Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collectfileindex.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 // skip indexing if index exists
60 if (Main\Context::getCurrent()->getRequest()->get('checkIndexExists') === 'Y')
61 {
62 $indexPath = Translate\Index\PathIndex::loadByPath($path);
63 if ($indexPath instanceof Translate\Index\PathIndex)
64 {
65 if ($indexPath->getIndexed())
66 {
67 return [
68 'STATUS' => Translate\Controller\STATUS_COMPLETED
69 ];
70 }
71 }
72 }
73
74 if ($this->isNewProcess)
75 {
76 $languages = $this->controller->getRequest()->get('languages');
77 if (\is_array($languages) && !\in_array('all', $languages))
78 {
79 $languages = \array_intersect($languages, Translate\Config::getEnabledLanguages());
80 if (!empty($languages))
81 {
82 $this->languages = $languages;
83 }
84 }
85
86 $filter = new Translate\Filter(['path' => $path]);
87 if (!empty($this->languages))
88 {
89 $filter->langId = $this->languages;
90 }
91
92 $this->totalItems = (new Index\FileIndexCollection())->countItemsToProcess($filter);
93
95
96 $this->instanceTimer()->setTimeLimit(5);
97 $this->isNewProcess = false;
98 }
99 else
100 {
101 $progressParams = $this->getProgressParameters();
102
103 if (isset($progressParams['totalItems']) && (int)$progressParams['totalItems'] > 0)
104 {
105 $this->totalItems = (int)$progressParams['totalItems'];
106 $this->processedItems = (int)$progressParams['processedItems'];
107 }
108
109 if (isset($progressParams['seekPathId']))
110 {
111 $this->seekPathId = $progressParams['seekPathId'];
112 }
113 }
114
115 return $this->performStep('runIndexing', ['path' => $path]);
116 }
117
125 private function runIndexing(array $params): array
126 {
127 $path = \rtrim($params['path'], '/');
128
129 $seek = new Translate\Filter();
130 if (!empty($this->seekPathId))
131 {
132 $seek->pathId = $this->seekPathId;
133 }
134
135 $filter = new Translate\Filter(['path' => $path]);
136 if (!empty($this->languages))
137 {
138 $filter->langId = $this->languages;
139 }
140
141 $indexer = new Index\FileIndexCollection();
142
143 $processedItemCount = $indexer->collect($filter, $this->instanceTimer(), $seek);
144
145 $this->processedItems += $processedItemCount;
146
147 if ($this->processedItems >= $this->totalItems)
148 {
149 $this->declareAccomplishment();
151 }
152 else
153 {
154 $this->seekPathId = $seek->nextPathId;
155 }
156
157 return [
158 'PROCESSED_ITEMS' => $this->processedItems,
159 'TOTAL_ITEMS' => $this->totalItems,
160 ];
161 }
162}
static getCurrent()
Definition context.php:241
__construct($name, Main\Engine\Controller $controller, array $config=[])
performStep($action, array $params=[])
Definition stepper.php:75
declareAccomplishment(bool $flag=true)
Definition stepper.php:136