- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/message/tester.php
- Класс: Bitrix\Sender\Message\Tester
- Вызов: Tester::send
public function send(array $codes, array $parameters)
{
$result = new Result();
if (!$this->isSupport())
{
$result->addError(new Error("Testing not supported."));
return $result;
}
// agreement accept check
if(!Security\User::current()->isAgreementAccepted())
{
$result->addError(new Error(Security\Agreement::getErrorText(), 'NEED_ACCEPT_AGREEMENT'));
return $result;
}
$campaignId = isset($parameters['CAMPAIGN_ID']) ? $parameters['CAMPAIGN_ID'] : Entity\Campaign::getDefaultId(SITE_ID);
$name = isset($parameters['NAME']) ? $parameters['NAME'] : null;
$name = $name ?: $GLOBALS['USER']->getFirstName();
$userId = isset($parameters['USER_ID']) ? $parameters['USER_ID'] : null;
$userId = $userId ?: $GLOBALS['USER']->getID();
$fields = isset($parameters['FIELDS']) ? $parameters['FIELDS'] : array();
$this->message->getTransport()->start();
$count = 0;
foreach ($codes as $code)
{
if (self::MAX_SEND_CODES && $count++ >= self::MAX_SEND_CODES)
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_MAX_COUNT', ['%count%' => self::MAX_SEND_CODES])));
return $result;
}
if ($this->message->getTransport()->isLimitsExceeded($this->message))
{
$limiter = $this->message->getTransport()->getExceededLimiter();
// special message for portal verification
if (($limiter instanceof CountLimiter) && $limiter->getName() === 'portal_verify')
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_LIMIT_PORTAL_VERIFY_FAILED', array('%name%' => $code))));
return $result;
}
if (!($limiter instanceof TimeLimiter))
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_LIMIT_EXCEEDED', array('%name%' => $code))));
return $result;
}
}
if (Integration\Bitrix24\Service::isCloud())
{
if ($this->message->getCode() === Message\IBase::CODE_MAIL) {
$verifyLimit = Integration\Bitrix24\Limitation\PortalVerifyLimit::instance();
if ($verifyLimit->getCurrent() >= $verifyLimit->getLimit())
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_LIMIT_PORTAL_VERIFY_FAILED', array('%name%' => $code))));
return $result;
}
}
$testerDailyLimit = Integration\Bitrix24\Limitation\TesterDailyLimit::instance();
if ($testerDailyLimit->getCurrent() >= $testerDailyLimit->getLimit())
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_LIMIT_EXCEEDED', array('%name%' => $code))));
return $result;
}
}
$type = Recipient\Type::detect($code);
if ($type)
{
$code = Recipient\Normalizer::normalize($code, $type);
}
if (!$type || !$code)
{
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_WRONG_RECIPIENT', array('%name%' => $code))));
continue;
}
$recipient = array(
'ID' => 0,
'CAMPAIGN_ID' => $campaignId,
'CONTACT_CODE' => $code,
'CONTACT_TYPE' => $type,
'NAME' => $name,
'USER_ID' => $userId,
'FIELDS' => $fields,
);
Posting\Sender::applyRecipientToMessage($this->message, $recipient, true);
try
{
$sendResult = $this->message->send();
if (!$sendResult && $result->isSuccess())
{
$to = $this->message->getRecipientCode();
$result->addError(new Error(Loc::getMessage('SENDER_MESSAGE_TESTER_ERROR_SENT', array('%name%' => $to))));
}
if ($sendResult)
{
$this->addLastCode($code);
if (Integration\Bitrix24\Service::isCloud() && $this->message->getCode() === Message\iBase::CODE_MAIL)
{
Integration\Bitrix24\Limitation\DailyLimit::increment();
Integration\Bitrix24\Limitation\TesterDailyLimit::increment();
}
}
}
catch(SystemException $e)
{
$result->addError(new Error($e->getMessage()));
break;
}
}
$this->message->getTransport()->end();
return $result;
}