22 if (!Loader::includeModule(self::$moduleId))
30 $connection = \Bitrix\Main\Application::getConnection();
31 if (!$connection->isTableExists(
'b_translate_phrase'))
38 $connection->query(
"SELECT `PHRASE` FROM `b_translate_phrase` WHERE 1=0");
47 !\Bitrix\Main\ModuleManager::isModuleInstalled(
'bitrix24')
48 && (php_sapi_name() ===
'cli');
52 $params = Option::get(self::$moduleId, self::OPTION_NAME,
'');
53 $params = $params !==
'' ? @unserialize($params, [
'allowed_classes' =>
false]) : [];
54 $params = is_array($params) ? $params : [];
63 'count' => LanguageTable::getCount() + 2,
67 if ($params[
'count'] > 0)
70 $result[
'progress'] = 1;
71 $result[
'steps'] =
'';
72 $result[
'count'] = $params[
'count'];
75 if (!empty($params[
'languages']))
77 $filter[
'!=ID'] = $params[
'languages'];
80 $langList = LanguageTable::getList([
83 'order' => [
'SORT' =>
'ASC'],
85 while ($row = $langList->fetch())
87 $langId = mb_strtolower($row[
'ID']);
88 if (!preg_match(
"/[a-z0-9]{2}/i", $langId))
95 Index\Internals\PhraseFts::createTable($langId);
96 $partitionTable = Index\Internals\PhraseFts::getPartitionTableName($langId);
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}'
106 $params[
'languages'][] = $langId;
109 if (!$isCronRun && (time() - $startTime >= 30))
115 if ($found ===
false)
117 if ($params[
'index'] ===
false)
121 $connection->queryExecute(
"ALTER TABLE `b_translate_phrase` DROP INDEX `IXF_TRNSL_PHR`");
125 $params[
'index'] =
true;
129 elseif ($params[
'field'] ===
false)
133 $connection->queryExecute(
"ALTER TABLE `b_translate_phrase` DROP COLUMN `PHRASE`");
137 $params[
'field'] =
true;
145 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
149 $result[
'progress'] = floor($params[
'number'] * 100 / $params[
'count']);
150 $result[
'steps'] = $params[
'number'];
152 if ($found ===
false)
154 Option::delete(self::$moduleId, [
'name' => self::OPTION_NAME]);