- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/posting/sender.php
- Класс: BitrixSenderPostingSender
- Вызов: Sender::send
public function send()
{
$this->load($this->letter->get('POSTING_ID'));
if (!$this->postingId)
{
$this->resultCode = self::RESULT_ERROR;
return;
}
if ($this->threadStrategy->isProcessLimited())
{
$this->resultCode = static::RESULT_CONTINUE;
return;
}
$threadState = $this->threadStrategy->checkThreads();
$this->startTime();
$this->isConsentSupport = $this->letter
->getMessage()
->getConfiguration()
->get('APPROVE_CONFIRMATION') === 'Y';
$this->threadStrategy->setPostingId($this->postingId);
if ($threadState === AbstractThreadStrategy::THREAD_NEEDED)
{
$this->threadStrategy->fillThreads();
}
$this->threadStrategy->lockThread();
$threadId = $this->threadStrategy->getThreadId();
// lock posting for exclude double parallel sending
if (is_null($threadId))
{
if (!$this->threadStrategy->hasUnprocessedThreads())
{
// update status of posting
$status = self::updateActualStatus(
$this->postingId,
$this->isPrevented()
);
$this->finalizePosting($status);
return;
}
$this->resultCode = static::RESULT_CONTINUE;
return;
}
if (static::lock($this->postingId, $threadId) === false)
{
$this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
throw new DBException(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_LOCK'));
}
if ($this->status == PostingTable::STATUS_NEW && $threadId !== 0)
{
$this->resultCode = static::RESULT_CONTINUE;
$this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
static::unlock($this->postingId, $threadId);
return;
}
// posting not in right status
if (!$this->initRecipients())
{
$this->resultCode = static::RESULT_WAITING_RECIPIENT;
$this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
static::unlock($this->postingId, $threadId);
return;
}
$this->changeStatusToPart();
// posting not in right status
if ($this->status != PostingTable::STATUS_PART)
{
$this->resultCode = static::RESULT_ERROR;
$this->threadStrategy->updateStatus(PostingThreadTable::STATUS_NEW);
static::unlock($this->postingId, $threadId);
return;
}
if ($this->isTransportLimitsExceeded())
{
$this->resultCode = static::RESULT_CONTINUE;
static::unlock($this->postingId, $threadId);
return;
}
$threadRecipients = $this->threadStrategy->getRecipients($this->limit);
$recipients = static::getRecipientsToSend($threadRecipients);
if (($count = count($recipients))> 0)
{
$this->message->getTransport()->setSendCount($count);
if (!$this->message->getTransport()->start())
{
$this->prevent();
}
}
$this->sendToRecipients($recipients);
$this->message->getTransport()->end();
// unlock posting for exclude double parallel sending
self::unlock($this->postingId, $threadId);
// update status of posting
$status = self::updateActualStatus(
$this->postingId,
$this->isPrevented(),
$this->threadStrategy->hasUnprocessedThreads()
);
$threadStatus = (
$threadRecipients->getSelectedRowsCount() === 0 ?
PostingThreadTable::STATUS_DONE :
PostingThreadTable::STATUS_NEW
);
$this->threadStrategy->updateStatus($threadStatus);
if ($threadId < $this->threadStrategy->lastThreadId())
{
$this->resultCode = static::RESULT_CONTINUE;
return;
}
if ($this->threadStrategy->hasUnprocessedThreads())
{
$this->resultCode = static::RESULT_CONTINUE;
return;
}
$this->finalizePosting($status);
}