Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
IncomingMessage.php
1
<?php
2
3
namespace
Bitrix\MessageService
;
4
5
use
Bitrix\Main\Config\Option
;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\ORM\Data\AddResult
;
8
use
Bitrix\Main\Type\DateTime
;
9
use
Bitrix\Messageservice\Internal\Entity\IncomingMessageTable
;
10
11
abstract
class
IncomingMessage
12
{
13
abstract
public
static
function
sendMessageToChat
(array $message);
14
abstract
protected
static
function
prepareBodyForSave
(array $body): array;
15
16
public
static
function
addMessage
(
string
$senderId, array $requestBody):
AddResult
17
{
18
$requestBody = static::prepareBodyForSave($requestBody);
19
20
$addResult =
new
AddResult
();
21
$insertingData = [
22
'SENDER_ID'
=> $senderId,
23
'EXTERNAL_ID'
=> $requestBody[
'id'
],
24
'REQUEST_BODY'
=> serialize($requestBody)
25
];
26
27
try
28
{
29
$addResult =
IncomingMessageTable::add
($insertingData);
30
}
31
catch
(\Throwable $exception)
32
{
33
if
(mb_strpos($exception->getMessage(),
'1062'
))
34
{
35
$addResult->addError(
new
Error
($exception->getMessage()));
36
37
return
$addResult;
38
}
39
40
throw
$exception;
41
}
42
43
return
$addResult;
44
}
45
46
public
static
function
confirmSendingMessage
(
int
$internalId): void
47
{
48
IncomingMessageTable::update
($internalId, [
49
'DATE_EXEC'
=>
new
DateTime
()
50
]);
51
}
52
53
public
static
function
cleanUpAgent
(): string
54
{
55
$period = abs((
int
)Option::get(
"messageservice"
,
"clean_up_period"
));
56
$periodInSeconds = $period * 24 * 3600;
57
58
if
($periodInSeconds > 0)
59
{
60
$connection = \Bitrix\Main\Application::getConnection();
61
$datetime = $connection->getSqlHelper()->addSecondsToDateTime(
'-'
. $periodInSeconds);
62
$connection->queryExecute(
"DELETE FROM b_messageservice_incoming_message WHERE DATE_EXEC <= {$datetime}"
);
63
}
64
65
return
__METHOD__.
'();'
;
66
}
67
}
Bitrix\Bizproc\Error
Definition
error.php:8
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\ORM\Data\AddResult
Definition
addresult.php:12
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\MessageService\IncomingMessage
Definition
IncomingMessage.php:12
Bitrix\MessageService\IncomingMessage\confirmSendingMessage
static confirmSendingMessage(int $internalId)
Definition
IncomingMessage.php:46
Bitrix\MessageService\IncomingMessage\prepareBodyForSave
static prepareBodyForSave(array $body)
Bitrix\MessageService\IncomingMessage\cleanUpAgent
static cleanUpAgent()
Definition
IncomingMessage.php:53
Bitrix\MessageService\IncomingMessage\addMessage
static addMessage(string $senderId, array $requestBody)
Definition
IncomingMessage.php:16
Bitrix\MessageService\IncomingMessage\sendMessageToChat
static sendMessageToChat(array $message)
Bitrix\Messageservice\Internal\Entity\IncomingMessageTable
Definition
incomingmessage.php:27
Bitrix\MessageService
modules
messageservice
lib
IncomingMessage.php
Создано системой
1.10.0