Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
chatindex.php
1
<?
2
namespace
Bitrix\Im\Update
;
3
4
use
Bitrix\Im\Chat
;
5
use
Bitrix\Im\Model\ChatTable
;
6
use
Bitrix\Main\Update\Stepper
;
7
use
Bitrix\Main\Localization\Loc
;
8
use
Bitrix\Main\Loader
;
9
use
Bitrix\Main\Config\Option
;
10
11
12
Loc::loadMessages
(__FILE__);
13
14
final
class
ChatIndex
extends
Stepper
15
{
16
const
OPTION_NAME
=
"im_index_chat"
;
17
protected
static
$moduleId
=
"im"
;
18
22
public
function
execute
(array &$result)
23
{
24
if
(!Loader::includeModule(self::$moduleId))
25
{
26
return
false
;
27
}
28
29
$return =
false
;
30
31
$params = Option::get(self::$moduleId, self::OPTION_NAME,
""
);
32
$params = ($params !==
""
? @unserialize($params, [
'allowed_classes'
=>
false
]) : []);
33
$params = (is_array($params) ? $params : []);
34
35
if
(empty($params))
36
{
37
$lastIdQuery =
38
ChatTable::query()
39
->addSelect(
'ID'
)
40
->whereIn(
'TYPE'
, [
Chat::TYPE_OPEN
,
Chat::TYPE_GROUP
])
41
->setOrder([
'ID'
=>
'DESC'
])
42
->setLimit(1)
43
->fetch()
44
;
45
$params = [
46
"lastId"
=> (int)$lastIdQuery[
'ID'
] + 1,
47
"number"
=> 0,
48
"count"
=> ChatTable::getCount([
49
'=TYPE'
=> [
Chat::TYPE_OPEN
,
Chat::TYPE_GROUP
],
50
]),
51
];
52
}
53
54
if
($params[
"count"
] > 0)
55
{
56
$result[
"title"
] =
Loc::getMessage
(
"IM_UPDATE_CHAT_INDEX"
);
57
$result[
"progress"
] = 1;
58
$result[
"steps"
] =
""
;
59
$result[
"count"
] = $params[
"count"
];
60
61
$cursor = ChatTable::getList([
62
'order'
=> [
'ID'
=>
'DESC'
],
63
'filter'
=> [
64
'<ID'
=> $params[
"lastId"
],
65
'=TYPE'
=> [
Chat::TYPE_OPEN
,
Chat::TYPE_GROUP
],
66
],
67
'select'
=> [
'ID'
,
'ENTITY_TYPE'
],
68
'offset'
=> 0,
69
'limit'
=> 500
70
]);
71
72
$found =
false
;
73
while
($row = $cursor->fetch())
74
{
75
if
($row[
'ENTITY_TYPE'
] !=
'LIVECHAT'
)
76
{
77
\CIMChat::index($row[
'ID'
]);
78
}
79
80
$params[
"lastId"
] = $row[
'ID'
];
81
$params[
"number"
]++;
82
$found =
true
;
83
}
84
85
if
($found)
86
{
87
Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
88
$return =
true
;
89
}
90
91
$result[
"progress"
] = intval($params[
"number"
] * 100/ $params[
"count"
]);
92
$result[
"steps"
] = $params[
"number"
];
93
94
if
($found ===
false
)
95
{
96
Option::delete(self::$moduleId, [
"name"
=> self::OPTION_NAME]);
97
if
(!IsModuleInstalled(
'bitrix24'
))
98
{
99
\CAdminNotify::Add([
100
"MESSAGE"
=>
Loc::getMessage
(
101
'IM_UPDATE_CHAT_INDEX_OPTIMIZE'
,
102
[
'#B_TAG_START#'
=>
'<b>'
,
'#B_TAG_END#'
=>
'</b>'
]
103
),
104
"TAG"
=>
"IM_CHAT_INDEX_OPTIMIZE_1"
,
105
"MODULE_ID"
=>
"IM"
,
106
]);
107
}
108
}
109
}
110
return
$return;
111
}
112
}
113
?>
Bitrix\Im\Chat
Definition
chat.php:19
Bitrix\Im\Chat\TYPE_OPEN
const TYPE_OPEN
Definition
chat.php:22
Bitrix\Im\Chat\TYPE_GROUP
const TYPE_GROUP
Definition
chat.php:24
Bitrix\Im\Model\ChatTable
Definition
chat.php:55
Bitrix\Im\Update\ChatIndex
Definition
chatindex.php:15
Bitrix\Im\Update\ChatIndex\execute
execute(array &$result)
Definition
chatindex.php:22
Bitrix\Im\Update\ChatIndex\$moduleId
static $moduleId
Definition
chatindex.php:17
Bitrix\Im\Update\ChatIndex\OPTION_NAME
const OPTION_NAME
Definition
chatindex.php:16
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Update\Stepper
Definition
stepper.php:27
Bitrix\Im\Update
Definition
bot.php:2
modules
im
lib
update
chatindex.php
Создано системой
1.10.0