16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
20 private $seekPath =
'';
23 private $seekOffset = 0;
26 private $pathList = [];
29 private $languages = [];
41 $this->
keepField([
'seekPath',
'pathList',
'seekOffset',
'languages']);
53 public function run($path =
'', $runBefore =
false)
62 $path = Translate\Config::getDefaultPath();
65 $path =
'/'. \trim($path,
'/.\\');
68 if ($this->isNewProcess)
70 $pathList = $this->controller->getRequest()->get(
'pathList');
72 if (!empty($pathList))
74 $pathList = \preg_split(
"/[\r\n]+/", $pathList);
75 \array_walk($pathList,
'trim');
76 $pathList = \array_unique(\array_filter($pathList));
84 $checkIndexExists = $this->controller->getRequest()->get(
'checkIndexExists') ===
'Y';
86 foreach ($pathList as $testPath)
88 if ($checkIndexExists)
90 $indexPath = Index\PathIndex::loadByPath($testPath);
91 if ($indexPath instanceof Index\
PathIndex)
93 if ($indexPath->getIndexed())
100 if (Translate\
IO\Path::isPhpFile($testPath))
102 if (!Translate\
IO\Path::isLangDir($testPath))
108 $this->pathList[] = $testPath;
111 if (empty($this->pathList))
114 'STATUS' => Translate\Controller\STATUS_COMPLETED,
118 $languages = $this->controller->getRequest()->get(
'languages');
119 if (\is_array($languages) && !\in_array(
'all', $languages))
121 $languages = \array_intersect($languages, Translate\Config::getEnabledLanguages());
122 if (!empty($languages))
124 $this->languages = $languages;
128 $this->isNewProcess =
false;
140 private function runIndexing(): array
144 $processedItemCount = 0;
146 for ($pos = ((
int)$this->seekOffset > 0 ? (
int)$this->seekOffset : 0), $total = \count($this->pathList); $pos < $total; $pos ++)
150 if (!empty($this->languages))
152 $filter->langId = $this->languages;
155 $testPath = $this->pathList[$pos];
156 if (\preg_match(
"#(.+/lang)(/?\w*)#", $testPath, $matches))
158 $filter->path = $matches[1];
159 $indexer->purge($filter);
161 $processedItemCount += $indexer->collect($filter);
165 $filter->path = $testPath;
168 $seek->lookForSeek =
false;
170 if (!empty($this->seekPath))
172 $seek->path = $this->seekPath;
173 $seek->lookForSeek =
true;
177 $indexer->purge($filter);
180 $processedItemCount += $indexer->collect($filter, $this->
instanceTimer(), $seek);
184 if (isset($seek->nextPath))
186 $this->seekPath = $seek->nextPath;
191 $this->seekPath =
null;
195 if (\connection_status() !== \CONNECTION_NORMAL)
197 throw new Main\SystemException(
'Process has been broken course user aborted connection.');
200 if (isset($this->pathList[$pos + 1]))
202 $this->seekOffset = $pos + 1;
206 $this->seekOffset =
null;
217 $this->processedItems += $processedItemCount;
218 $this->totalItems += $processedItemCount;
222 $this->processedItems = $this->totalItems = (
new Index\PathIndexCollection())->countItemsToProcess($filter);