1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
phrasefts.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Translate\Index\Internals;
4
5
use Bitrix\Main\Application;
6
use Bitrix\Main\DB\SqlQueryException;
7
use Bitrix\Main\ORM;
8
use Bitrix\Main\ORM\Data\DataManager;
9
use Bitrix\Main\ArgumentException;
10
use Bitrix\Translate;
11
use Bitrix\Translate\Index;
12
13
14
abstract
class
PhraseFts
extends
DataManager
15
{
16
use
Index\Internals\BulkOperation
;
17
19
protected
static
array
$ftsEntities
= [];
20
26
public
static
function
getMap
():
array
27
{
28
return
[
29
'ID'
=> [
30
'data_type'
=>
'integer'
,
31
'primary'
=>
true
,
32
],
33
'FILE_ID'
=> [
34
'data_type'
=>
'integer'
,
35
],
36
'PATH_ID'
=> [
37
'data_type'
=>
'integer'
,
38
],
39
'CODE'
=> [
40
'data_type'
=>
'string'
,
41
],
42
'PHRASE'
=> [
43
'data_type'
=>
'string'
,
44
],
45
'FILE'
=> [
46
'data_type'
=> Index\Internals\FileIndexTable::class,
47
'reference'
=> [
48
'=this.FILE_ID'
=>
'ref.ID'
,
49
],
50
'join_type'
=>
'INNER'
,
51
],
52
'PATH'
=> [
53
'data_type'
=> Index\Internals\PathIndexTable::class,
54
'reference'
=> [
55
'=this.PATH_ID'
=>
'ref.ID'
,
56
],
57
'join_type'
=>
'INNER'
,
58
],
59
];
60
}
61
66
public
static
function
checkTables
(): void
67
{
68
$tables = [];
69
$tablesRes = Application::getConnection()->query(
"SHOW TABLES LIKE 'b_translate_phrase_fts_%'"
);
70
while
($row = $tablesRes->fetch())
71
{
72
$tableName = array_shift($row);
73
$langId = substr($tableName, -2);
74
$tables[$langId] = $tableName;
75
}
76
foreach
(
Translate
\Config::getEnabledLanguages() as $langId)
77
{
78
if
(!preg_match(
"/[a-z0-9]{2}/i"
, $langId))
79
{
80
continue
;
81
}
82
if
(!isset($tables[$langId]))
83
{
84
self::createTable
($langId);
85
}
86
else
87
{
88
unset($tables[$langId]);
89
}
90
}
91
foreach
($tables as $langId =>
$table
)
92
{
93
self::dropTable
($langId);
94
}
95
}
96
102
public
static
function
getPartitionTableName
(
string
$langId): string
103
{
104
if
(!in_array($langId,
Translate
\Config::getLanguages(skipCache:
true
),
true
))
105
{
106
throw
new
ArgumentException
(
'Parameter langId has wrong value'
);
107
}
108
109
return
"b_translate_phrase_fts_{$langId}"
;
110
}
111
118
public
static
function
createTable
(
string
$langId): void
119
{
120
$partitionTable =
self::getPartitionTableName
($langId);
121
122
$suffix = mb_strtoupper($langId);
123
124
Application::getConnection()->queryExecute(
"
125
CREATE TABLE IF NOT EXISTS `{$partitionTable}` (
126
`ID` int not null,
127
`FILE_ID` int not null,
128
`PATH_ID` int not null,
129
`CODE` varbinary(255) not null,
130
`PHRASE` text,
131
PRIMARY KEY (`ID`),
132
UNIQUE KEY `IXU_TRNSL_FTS_PT_{$suffix}` (`PATH_ID`, `CODE`),
133
UNIQUE KEY `IXU_TRNSL_FTS_FL_{$suffix}` (`FILE_ID`, `CODE`),
134
FULLTEXT INDEX `IXF_TRNSL_FTS_PH_{$suffix}` (`PHRASE`)
135
) DELAY_KEY_WRITE=1
136
"
);
137
}
138
145
public
static
function
dropTable
(
string
$langId): void
146
{
147
$partitionTable =
self::getPartitionTableName
($langId);
148
149
Application::getConnection()->queryExecute(
"DROP TABLE IF EXISTS `{$partitionTable}`"
);
150
}
151
157
public
static
function
getFtsEntityClass
(
string
$langId): string
158
{
159
static
$cache = [];
160
if
(!isset($cache[$langId]))
161
{
162
$entity
=
self::getFtsEntity
($langId);
163
$cache[$langId] =
$entity
->getDataClass();
164
}
165
166
return
$cache[$langId];
167
}
168
174
public
static
function
getFtsEntity
(
string
$langId):
ORM
\
Entity
175
{
176
if
(!in_array($langId,
Translate
\Config::getEnabledLanguages(),
true
))
177
{
178
throw
new
ArgumentException
(
'Parameter langId has wrong value'
);
179
}
180
if
(!isset(self::$ftsEntities[$langId]))
181
{
182
self::$ftsEntities[$langId] = ORM\Entity::compileEntity(
183
'PhraseIndexTfsEntity'
. mb_strtoupper($langId),
184
[],
185
[
186
'table_name'
=> self::getPartitionTableName($langId),
187
'namespace'
=> __NAMESPACE__,
188
'parent'
=>
Index
\
Internals
\PhraseFts::class
189
]
190
);
191
}
192
193
return
self::$ftsEntities[$langId];
194
}
195
203
public
static
function
purge
(?
Translate
\
Filter
$filter
=
null
): void
204
{
205
$filterOut = static::processFilter(
$filter
);
206
static::bulkDelete($filterOut);
207
}
208
216
public
static
function
processFilter
(?
Translate
\
Filter
$filter
=
null
):
array
217
{
218
$filterOut = [];
219
220
if
(
$filter
!==
null
)
221
{
222
foreach
(
$filter
as
$key
=> $value)
223
{
224
if
(empty($value) && $value !==
'0'
)
225
{
226
continue
;
227
}
228
229
if
(
$key
===
'path'
)
230
{
231
$filterOut[
'=%PATH.PATH'
] = $value.
'%'
;
232
}
233
elseif
(
$key
===
'fileId'
)
234
{
235
$filterOut[
'=FILE_ID'
] = $value;
236
}
237
elseif
(
$key
===
'pathId'
)
238
{
239
$filterOut[
'=PATH_ID'
] = $value;
240
}
241
else
242
{
243
if
(static::getEntity()->hasField(trim(
$key
,
'<>!=@~%*'
)))
244
{
245
$filterOut[
$key
] = $value;
246
}
247
}
248
}
249
}
250
251
return
$filterOut;
252
}
253
261
public
static
function
onLanguageDelete
($param): void
262
{
263
$langId =
null
;
264
if
($param instanceof \
Bitrix
\
Main
\
ORM
\
Event
)
265
{
266
$langId = $param->getParameter(
'primary'
)[
'LID'
];
267
}
268
elseif
(is_string($param))
269
{
270
$langId = $param;
271
}
272
if
($langId)
273
{
274
self::dropTable
($langId);
275
}
276
}
277
285
public
static
function
onLanguageAdd
($param): void
286
{
287
$langId =
null
;
288
if
($param instanceof \
Bitrix
\
Main
\
ORM
\
Event
)
289
{
290
$langId = $param->getParameter(
'primary'
)[
'LID'
];
291
}
292
elseif
(is_array($param))
293
{
294
$langId = $param[
'LID'
];
295
}
296
if
($langId)
297
{
298
self::createTable
($langId);
299
}
300
}
301
}
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\ORM\Data\DataManager
Определения
datamanager.php:35
Bitrix\Main\ORM\Data\DataManager\$entity
static $entity
Определения
datamanager.php:47
Bitrix\Translate\Index\Internals\PhraseFts
Определения
phrasefts.php:15
Bitrix\Translate\Index\Internals\PhraseFts\getMap
static getMap()
Определения
phrasefts.php:26
Bitrix\Translate\Index\Internals\PhraseFts\onLanguageAdd
static onLanguageAdd($param)
Определения
phrasefts.php:285
Bitrix\Translate\Index\Internals\PhraseFts\getFtsEntityClass
static getFtsEntityClass(string $langId)
Определения
phrasefts.php:157
Bitrix\Translate\Index\Internals\PhraseFts\processFilter
static processFilter(?Translate\Filter $filter=null)
Определения
phrasefts.php:216
Bitrix\Translate\Index\Internals\PhraseFts\dropTable
static dropTable(string $langId)
Определения
phrasefts.php:145
Bitrix\Translate\Index\Internals\PhraseFts\getFtsEntity
static getFtsEntity(string $langId)
Определения
phrasefts.php:174
Bitrix\Translate\Index\Internals\PhraseFts\$ftsEntities
static array $ftsEntities
Определения
phrasefts.php:19
Bitrix\Translate\Index\Internals\PhraseFts\checkTables
static checkTables()
Определения
phrasefts.php:66
Bitrix\Translate\Index\Internals\PhraseFts\getPartitionTableName
static getPartitionTableName(string $langId)
Определения
phrasefts.php:102
Bitrix\Translate\Index\Internals\PhraseFts\purge
static purge(?Translate\Filter $filter=null)
Определения
phrasefts.php:203
Bitrix\Translate\Index\Internals\PhraseFts\createTable
static createTable(string $langId)
Определения
phrasefts.php:118
Bitrix\Translate\Index\Internals\PhraseFts\onLanguageDelete
static onLanguageDelete($param)
Определения
phrasefts.php:261
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$filter
$filter
Определения
iblock_catalog_list.php:54
Bitrix\Main\Entity
Определения
ufield.php:9
Bitrix\Main\Filter
Bitrix\Main\ORM
Bitrix\Main
Bitrix\Main\$table
$table
Определения
mysql_to_pgsql.php:36
Bitrix\Translate\Index\Internals
Определения
bulkoperation.php:3
Bitrix\Translate\Index\Internals\BulkOperation
trait BulkOperation
Определения
bulkoperation.php:9
Bitrix\Translate\Index
Определения
aggregate.php:3
Bitrix\Translate
Определения
autoload.php:3
Bitrix
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
bitrix
modules
translate
lib
index
internals
phrasefts.php
Создано системой
1.14.0