2namespace Bitrix\MessageService;
4use Bitrix\Main\Localization\Loc;
5use Bitrix\Main\ArgumentTypeException;
6use Bitrix\Main\ORM\Data\AddResult;
9use Bitrix\Main\Type\DateTime;
10use Bitrix\MessageService\Integration\Pull;
11use Bitrix\MessageService\Internal\Entity\MessageTable;
12use Bitrix\MessageService\Restriction\RestrictionManager;
13use Bitrix\MessageService\Sender\Result;
15Loc::loadMessages(__FILE__);
73 $fields = MessageTable::getByExternalId($senderId, $externalId,
$from)->fetch();
136 $result->addError(
new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_SENDER')));
140 $result->addError(
new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_SENDER_CAN_USE')));
144 $result->addError(
new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_TYPE')));
148 $result->addError(
new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_FROM')));
163 if (!$checkResult->isSuccess())
166 $result->addErrors($checkResult->getErrors());
170 if ($this->checkRestrictions)
173 if (!$restrictionManager->isCanSendMessage())
176 new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_RESTRICTION'))
186 'SENDER_ID' =>
$sender->getId(),
187 'AUTHOR_ID' => $this->getAuthorId(),
188 'MESSAGE_FROM' => $this->getFrom(),
189 'MESSAGE_TO' => $this->getTo(),
191 'MESSAGE_BODY' => $this->
getBody(),
192 'CLUSTER_GROUP' => defined(
'BX_CLUSTER_GROUP') ? BX_CLUSTER_GROUP :
null
197 if (
Main\
Config\Option::get(
'messageservice',
'event_log_message_send',
'N') ===
'Y')
213 if (!$checkResult->isSuccess())
215 $result =
new Result\SendMessage();
216 return $result->addErrors($checkResult->getErrors());
219 if ($this->checkRestrictions)
222 if (!$restrictionManager->isCanSendMessage())
225 new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_RESTRICTION'))
232 if (!
Sender\Limitation::checkDailyLimit(
$sender->getId(), $this->getFrom()))
234 $result =
new Result\SendMessage();
235 $result->addError(
new Error(Loc::getMessage(
'MESSAGESERVICE_MESSAGE_ERROR_LIMITATION')));
244 'SENDER_ID' =>
$sender->getId(),
246 'MESSAGE_FROM' => $this->
getFrom(),
247 'MESSAGE_TO' => $this->
getTo(),
249 'MESSAGE_BODY' => $this->
getBody(),
250 'CLUSTER_GROUP' => defined(
'BX_CLUSTER_GROUP') ? BX_CLUSTER_GROUP : null
261 if (
$result->getExternalId() !==
null)
265 if (
$result->getStatus() !==
null)
271 if (!$addResult->isSuccess())
273 $result->addErrors($addResult->getErrors());
279 $this->
id = $addResult->getId();
282 if (
Main\
Config\Option::get(
'messageservice',
'event_log_message_send',
'N') ===
'Y')
305 $this->from = (string)
$from;
323 $this->body = (string)
$body;
341 $this->to = (string)
$to;
425 $updateResult = MessageTable::update($this->
id, $fields);
426 if (!$updateResult->isSuccess())
434 $eventFields = array_merge([
'ID' => $this->
id], $fields);
437 static::EVENT_MESSAGE_UPDATED,
447 $toUpdate = [
'SUCCESS_EXEC' =>
'E',
'DATE_EXEC' =>
new DateTime()];
450 $toUpdate[
'SUCCESS_EXEC'] =
'Y';
451 if (
$result->getExternalId() !==
null)
453 if (is_array(
$result->getExternalId()))
455 $systemException = new \Bitrix\Main\SystemException(
'ExternalId is array: ' . print_r(
$result->getExternalId(),
true));
459 'ExternalId is array',
465 $toUpdate[
'EXTERNAL_ID'] =
$result->getExternalId();
467 if (
$result->getStatus() !==
null)
469 $toUpdate[
'STATUS_ID'] =
$result->getStatus();
475 'SUCCESS_EXEC' =>
'N',
476 'NEXT_EXEC' => $nextExec,
488 $toUpdate[
'EXEC_ERROR'] = implode(PHP_EOL,
$errors);
499 $isUpdateSuccess = MessageTable::updateMessageStatuses(
505 if (!$isUpdateSuccess)
510 $this->statusId = $newInternalStatus;
516 static::EVENT_MESSAGE_UPDATED,
526 $updateResult = MessageTable::updateStatusId($this->
id, $newStatusId);
532 $this->statusId = $newStatusId;
538 static::EVENT_MESSAGE_UPDATED,
548 if (!$this->sender && isset(
$fields[
'SENDER_ID']))
558 $this->
id = (int)
$fields[
'ID'];
564 if (isset(
$fields[
'AUTHOR_ID']))
568 if (isset(
$fields[
'MESSAGE_FROM']))
572 if (isset(
$fields[
'MESSAGE_TO']))
577 isset(
$fields[
'MESSAGE_TEMPLATE'])
578 && $this->sender->isConfigurable()
579 && $this->sender->isTemplatesBased()
583 $fields[
'MESSAGE_HEADERS'][
'template'] = $this->sender->prepareTemplate(
$fields[
'MESSAGE_TEMPLATE']);
585 if (isset(
$fields[
'MESSAGE_HEADERS']) && is_array(
$fields[
'MESSAGE_HEADERS']))
589 if (isset(
$fields[
'MESSAGE_BODY']))
591 $messageBody = $this->sender
592 ? $this->sender->prepareMessageBodyForSave(
$fields[
'MESSAGE_BODY'])
597 if (isset(
$fields[
'STATUS_ID']))
599 $this->statusId =
$fields[
'STATUS_ID'];
601 if (isset(
$fields[
'EXTERNAL_STATUS']))
603 $this->externalStatus =
$fields[
'EXTERNAL_STATUS'];
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static onMessagesUpdate(array $messages)
setCheckRestrictions(bool $checkRestrictions)
updateWithSendResult(Result\SendMessage $result, DateTime $nextExec)
__construct(Sender\Base $sender=null)
updateStatus(int $newStatusId)
static createFromFields(array $fields, Sender\Base $sender=null)
setSender(Sender\Base $sender)
static getFieldsById($messageId)
updateStatusByExternalStatus(string $externalStatus)
setHeaders(array $headers)
static loadByExternalId(string $senderId, string $externalId, ?string $from=null)
setAuthorId(int $authorId)
const EVENT_MESSAGE_UPDATED
static isSupported($type)
static getSenderById($id)
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"