Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
IncomingMessage.php
1<?php
2
4
10
11abstract 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}
static update($primary, array $data)
static confirmSendingMessage(int $internalId)
static prepareBodyForSave(array $body)
static addMessage(string $senderId, array $requestBody)
static sendMessageToChat(array $message)