Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collectpathindex.php
1<?php
3
8
15{
16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
18
20 private $seekPathLangId = 0;
21
23 private $languages = [];
24
25
33 public function __construct($name, Main\Engine\Controller $controller, array $config = [])
34 {
35 $this->keepField(['seekPathLangId', 'languages']);
36
37 parent::__construct($name, $controller, $config);
38 }
39
46 public function run($path = '')
47 {
48 if (empty($path))
49 {
50 $path = Translate\Config::getDefaultPath();
51 }
52
53 if (\preg_match("#(.+\/lang)(\/?\w*)#", $path, $matches))
54 {
55 $path = $matches[1];
56 }
57
58 $path = '/'. \trim($path, '/.\\');
59
60 // skip indexing if index exists
61 if (Main\Context::getCurrent()->getRequest()->get('checkIndexExists') === 'Y')
62 {
63 $indexPath = Translate\Index\PathIndex::loadByPath($path);
64 if ($indexPath instanceof Translate\Index\PathIndex)
65 {
66 if ($indexPath->getIndexed())
67 {
68 return [
69 'STATUS' => Translate\Controller\STATUS_COMPLETED
70 ];
71 }
72 }
73 }
74
75 if ($this->isNewProcess)
76 {
77 $languages = $this->controller->getRequest()->get('languages');
78 if (\is_array($languages) && !\in_array('all', $languages))
79 {
80 $languages = \array_intersect($languages, Translate\Config::getEnabledLanguages());
81 if (!empty($languages))
82 {
83 $this->languages = $languages;
84 }
85 }
86
87 $indexer = new Index\PathIndexCollection();
88 $filter = new Translate\Filter(['path' => $path]);
89 if (!empty($this->languages))
90 {
91 $filter->langId = $this->languages;
92 }
93
94 $this->totalItems = $indexer->countItemsToProcess($filter);
95 $this->processedItems = 0;
96
98
99 $indexer->purge($filter);
100
101 /*
102 ->unvalidate($filter);
103 'indexedTime' => new Main\Type\DateTime(
104 date('Y-m-d H:i:s', strtotime('-'.self::EXPIRATION_DEPTH)),
105 'Y-m-d H:i:s'
106 )*/
107
108 $this->instanceTimer()->setTimeLimit(5);
109 $this->isNewProcess = false;
110 }
111 else
112 {
113 $progressParams = $this->getProgressParameters();
114
115 if (isset($progressParams['totalItems']) && (int)$progressParams['totalItems'] > 0)
116 {
117 $this->totalItems = (int)$progressParams['totalItems'];
118 $this->processedItems = (int)$progressParams['processedItems'];
119 }
120
121 if (isset($progressParams['seekPathLangId']))
122 {
123 $this->seekPathLangId = $progressParams['seekPathLangId'];
124 }
125 }
126
127 return $this->performStep('runIndexing', ['path' => $path]);
128 }
129
137 private function runIndexing(array $params): array
138 {
139 $path = \rtrim($params['path'], '/');
140
141 $seek = new Translate\Filter();
142 if (!empty($this->seekPathLangId))
143 {
144 $seek->pathLangId = $this->seekPathLangId;
145 }
146
147 $indexer = new Index\PathIndexCollection();
148
149 $filter = new Translate\Filter(['path' => $path]);
150
151 if ($this->processedItems >= $this->totalItems)
152 {
153 $indexer->validate($filter, false);
154 }
155 else
156 {
157 if (!empty($this->languages))
158 {
159 $filter->langId = $this->languages;
160 }
161
162 $processedItemCount = $indexer->collect($filter, $this->instanceTimer(), $seek);
163
164 $this->processedItems += $processedItemCount;
165 }
166
167 if ($this->processedItems >= $this->totalItems && $this->instanceTimer()->hasTimeLimitReached() !== true)
168 {
169 $this->declareAccomplishment();
171 }
172 else
173 {
174 $this->seekPathLangId = $seek->nextLangPathId;
175 }
176
177 return [
178 'PROCESSED_ITEMS' => $this->processedItems,
179 'TOTAL_ITEMS' => $this->totalItems,
180 ];
181 }
182}
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