31 if (isset($filter, $filter->path))
33 $relPath =
'/'. \trim($filter->path,
'/');
34 $relPath = Translate\IO\Path::replaceLangId($relPath,
'#LANG_ID#');
36 $topPathRes = Index\Internals\PathIndexTable::getList([
38 'filter' => [
'=PATH' => $relPath]
40 if (!($topPath = $topPathRes->fetch()))
45 $checkLanguages = Translate\Config::getEnabledLanguages();
46 if (isset($filter, $filter->langId))
48 $checkLanguages = \array_intersect($filter->langId, $checkLanguages);
52 '=PATH.DESCENDANTS.PARENT_ID' => $topPath[
'ID'],
53 '=LANG_ID' => $checkLanguages,
56 $totalItems = (int)Index\Internals\FileIndexTable::getCount($fileFilter);
60 $totalItems = (int)Index\Internals\FileIndexTable::getCount();
78 if (isset($filter, $filter->path))
80 $relPath = $filter->path;
84 $relPath = Translate\Config::getDefaultPath();
87 $relPath =
'/'. \trim($relPath,
'/');
88 $relPath = Translate\IO\Path::replaceLangId($relPath,
'#LANG_ID#');
90 $checkLanguages = Translate\Config::getEnabledLanguages();
91 if (isset($filter, $filter->langId))
93 $checkLanguages = \array_intersect($filter->langId, $checkLanguages);
96 $topPathRes = Index\Internals\PathIndexTable::getList([
98 'filter' => [
'=PATH' => $relPath]
100 if (!($topPath = $topPathRes->fetch()))
106 '=PATH.DESCENDANTS.PARENT_ID' => $topPath[
'ID'],
107 '=LANG_ID' => $checkLanguages,
110 if (isset($seek, $seek->pathId))
112 $fileFilter[
'>PATH_ID'] = $seek->pathId;
115 Main\Application::getConnection()->queryExecute(
"SET SESSION group_concat_max_len = 100000");
117 $fileListQuery = Index\Internals\FileIndexTable::query();
120 ->addSelect(
'PATH_ID')
122 ->registerRuntimeField(
new ExpressionField(
'FILE_IDS',
"GROUP_CONCAT(%s ORDER BY (%s) SEPARATOR '\\n')", [
'ID',
'ID']))
123 ->addSelect(
'FILE_IDS')
125 ->registerRuntimeField(
new ExpressionField(
'LANG_IDS',
"GROUP_CONCAT(%s ORDER BY (%s) SEPARATOR '\\n')", [
'LANG_ID',
'ID']))
126 ->addSelect(
'LANG_IDS')
128 ->registerRuntimeField(
new ExpressionField(
'FULL_PATHS',
"GROUP_CONCAT(%s ORDER BY (%s) SEPARATOR '\\n')", [
'FULL_PATH',
'ID']))
129 ->addSelect(
'FULL_PATHS')
131 ->setFilter($fileFilter)
132 ->setOrder([
'PATH_ID' =>
'ASC'])
133 ->addGroup(
'PATH_ID')
136 $fileListRes = $fileListQuery->exec();
138 $phraseId = Index\Internals\PhraseIndexTable::query()
139 ->registerRuntimeField(
new ExpressionField(
'MAXID',
'MAX(%s)', [
'ID']))
144 $processedItemCount = 0;
150 while ($pathRow = $fileListRes->fetch())
152 $filePortion[] = $pathRow;
153 if (\count($filePortion) >= 5)
158 if (empty($filePortion))
164 $phraseCodeData = [];
167 $nonexistentFiles = [];
169 foreach ($filePortion as $indexFile)
171 $pathId = (int)$indexFile[
'PATH_ID'];
172 $pathIdPortion[] = $lastPathId = $pathId;
175 foreach (\explode(
"\n", $indexFile[
'FILE_IDS']) as $v)
177 $fileIds[] = (int)$v;
181 foreach (\explode(
"\n", $indexFile[
'LANG_IDS']) as $v)
183 $langIds[] = \trim($v);
187 foreach (\explode(
"\n", $indexFile[
'FULL_PATHS']) as $v)
189 $filePaths[] = \trim($v);
192 foreach ($fileIds as $inx => $indexFileId)
194 $langId = $langIds[$inx];
195 $fullPath = $filePaths[$inx];
199 echo
"Lang file: {$fullPath}\n";
203 $current->setLangId($langId);
204 if (!$current->load())
206 $nonexistentFiles[] = $indexFileId;
211 'ID' => $indexFileId,
212 'PATH_ID' => $pathId,
213 'LANG_ID' => $langId,
214 'PHRASE_COUNT' => $current->count(),
215 'FULL_PATH' => $current->getPath(),
220 foreach ($current as $code => $phrase)
223 $phraseCodeData[] = [
225 'FILE_ID' => $indexFileId,
226 'PATH_ID' => $pathId,
227 'LANG_ID' => $langId,
230 if (!isset($phraseData[$langId]))
232 $phraseData[$langId] = [];
234 $phraseData[$langId][] = [
236 'FILE_ID' => $indexFileId,
237 'PATH_ID' => $pathId,
244 $processedItemCount += \count($fileIds);
248 Index\Internals\PhraseIndexTable::bulkDelete([
249 '=PATH_ID' => $pathIdPortion,
250 '=LANG_ID' => $checkLanguages,
253 if (\count($nonexistentFiles) > 0)
255 Index\Internals\PhraseIndexTable::bulkDelete([
'=FILE_ID' => $nonexistentFiles]);
256 Index\Internals\FileIndexTable::bulkDelete([
'=ID' => $nonexistentFiles]);
257 foreach (Translate\Config::getEnabledLanguages() as $langId)
259 $ftsClass = Index\Internals\PhraseFts::getFtsEntityClass($langId);
260 $ftsClass::bulkDelete([
'=FILE_ID' => $nonexistentFiles]);
265 if (\count($phraseCodeData) > 0)
267 Index\Internals\FileIndexTable::bulkAdd($fileData,
'ID');
268 Index\Internals\PhraseIndexTable::bulkAdd($phraseCodeData);
269 foreach ($phraseData as $langId => $phraseLangData)
271 $ftsClass = Index\Internals\PhraseFts::getFtsEntityClass($langId);
272 $ftsClass::bulkAdd($phraseLangData,
'ID');
276 Index\Internals\PathIndexTable::bulkUpdate(
277 [
'INDEXED' =>
'Y',
'INDEXED_TIME' =>
new Main\
Type\
DateTime()],
278 [
'=ID' => $pathIdPortion]
281 if ($timer !==
null && $timer->hasTimeLimitReached())
285 $seek->nextPathId = $lastPathId;
292 if ($timer ===
null || !$timer->hasTimeLimitReached())
294 Index\Internals\PathIndexTable::bulkUpdate(
295 [
'INDEXED' =>
'Y',
'INDEXED_TIME' =>
new Main\
Type\
DateTime()],
298 '=DESCENDANTS.PARENT_ID' => $topPath[
'ID'],
303 return $processedItemCount;