Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PhraseFtsIndexConverter.php
1<?php
3
10
11
13{
14 const OPTION_NAME = 'fts_index_converter_stepper';
15 protected static $moduleId = 'translate';
16
20 public function execute(array &$result)
21 {
22 if (!Loader::includeModule(self::$moduleId))
23 {
25 }
26
27 global $pPERIOD;
28 $pPERIOD = 30;
30 $connection = \Bitrix\Main\Application::getConnection();
31 if (!$connection->isTableExists('b_translate_phrase'))
32 {
34 }
35
36 try
37 {
38 $connection->query("SELECT `PHRASE` FROM `b_translate_phrase` WHERE 1=0");
39 }
40 catch (SqlException $exception)
41 {
43 }
44
45 $startTime = time();
46 $isCronRun =
47 !\Bitrix\Main\ModuleManager::isModuleInstalled('bitrix24')
48 && (php_sapi_name() === 'cli');
49
50 $return = self::FINISH_EXECUTION;
51
52 $params = Option::get(self::$moduleId, self::OPTION_NAME, '');
53 $params = $params !== '' ? @unserialize($params, ['allowed_classes' => false]) : [];
54 $params = is_array($params) ? $params : [];
55
56 if (empty($params))
57 {
58 $params = [
59 'languages' => [],
60 'index' => false,
61 'field' => false,
62 'number' => 0,
63 'count' => LanguageTable::getCount() + 2,
64 ];
65 }
66
67 if ($params['count'] > 0)
68 {
69 $result['title'] = Loc::getMessage('IM_UPDATE_CHAT_DISK_ACCESS');
70 $result['progress'] = 1;
71 $result['steps'] = '';
72 $result['count'] = $params['count'];
73
74 $filter = [];
75 if (!empty($params['languages']))
76 {
77 $filter['!=ID'] = $params['languages'];
78 }
79 $found = false;
80 $langList = LanguageTable::getList([
81 'select' => ['ID'],
82 'filter' => $filter,
83 'order' => ['SORT' => 'ASC'],
84 ]);
85 while ($row = $langList->fetch())
86 {
87 $langId = mb_strtolower($row['ID']);
88 if (!preg_match("/[a-z0-9]{2}/i", $langId))
89 {
90 continue;
91 }
92
93 try
94 {
95 Index\Internals\PhraseFts::createTable($langId);
96 $partitionTable = Index\Internals\PhraseFts::getPartitionTableName($langId);
97
98 $connection->queryExecute("
99 INSERT IGNORE INTO `{$partitionTable}`
100 SELECT `ID`, `FILE_ID`, `PATH_ID`, `CODE`, `PHRASE` FROM `b_translate_phrase` WHERE `LANG_ID` = '{$langId}'
101 ");
102 }
103 catch (SqlException $exception)
104 {}
105
106 $params['languages'][] = $langId;
107 $params['number']++;
108 $found = true;
109 if (!$isCronRun && (time() - $startTime >= 30))
110 {
111 break;
112 }
113 }
114
115 if ($found === false)
116 {
117 if ($params['index'] === false)
118 {
119 try
120 {
121 $connection->queryExecute("ALTER TABLE `b_translate_phrase` DROP INDEX `IXF_TRNSL_PHR`");
122 }
123 catch (SqlException $exception)
124 {}
125 $params['index'] = true;
126 $params['number']++;
127 $found = true;
128 }
129 elseif ($params['field'] === false)
130 {
131 try
132 {
133 $connection->queryExecute("ALTER TABLE `b_translate_phrase` DROP COLUMN `PHRASE`");
134 }
135 catch (SqlException $exception)
136 {}
137 $params['field'] = true;
138 $params['number']++;
139 $found = true;
140 }
141 }
142
143 if ($found)
144 {
145 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
146 $return = self::CONTINUE_EXECUTION;
147 }
148
149 $result['progress'] = floor($params['number'] * 100 / $params['count']);
150 $result['steps'] = $params['number'];
151
152 if ($found === false)
153 {
154 Option::delete(self::$moduleId, ['name' => self::OPTION_NAME]);
155 }
156 }
157
158 return $return;
159 }
160}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29