- Модуль: messageservice
- Путь к файлу: ~/bitrix/modules/messageservice/lib/message.php
- Класс: BitrixMessageServiceMessage
- Вызов: Message::send
public function send(): MainResult
{
global $USER;
$checkResult = $this->checkFields();
if (!$checkResult->isSuccess())
{
$result = new AddResult();
$result->addErrors($checkResult->getErrors());
return $result;
}
if ($this->checkRestrictions)
{
$restrictionManager = new RestrictionManager($this);
if (!$restrictionManager->isCanSendMessage())
{
return (new MainResult())->addError(
new Error(Loc::getMessage('MESSAGESERVICE_MESSAGE_ERROR_RESTRICTION'))
);
}
}
$sender = $this->getSender();
$headers = $this->getHeaders();
$result = InternalEntityMessageTable::add([
'TYPE' => $this->getType(),
'SENDER_ID' => $sender->getId(),
'AUTHOR_ID' => $this->getAuthorId(),
'MESSAGE_FROM' => $this->getFrom(),
'MESSAGE_TO' => $this->getTo(),
'MESSAGE_HEADERS' => count($headers) > 0 ? $headers : null,
'MESSAGE_BODY' => $this->getBody(),
'CLUSTER_GROUP' => defined('BX_CLUSTER_GROUP') ? BX_CLUSTER_GROUP : null
]);
if ($result->isSuccess())
{
$this->id = $result->getId();
if (MainConfigOption::get('messageservice', 'event_log_message_send', 'N') === 'Y')
{
$userId = is_object($USER) ? $USER->getId() : 0;
CEventLog::Log('INFO', 'MESSAGE_SEND', 'messageservice', $userId, $this->getTo());
}
}
return $result;
}