162 $this->
load($this->letter->get(
'POSTING_ID'));
164 if (!$this->postingId)
166 $this->resultCode = self::RESULT_ERROR;
168 AddMessage2Log(
'Mailing without id',
'sender');
173 if ($this->threadStrategy->isProcessLimited())
175 $this->resultCode = static::RESULT_CONTINUE;
179 $threadState = $this->threadStrategy->checkThreads();
183 $this->isConsentSupport = $this->letter
186 ->get(
'APPROVE_CONFIRMATION') ===
'Y';
188 $this->threadStrategy->setPostingId($this->postingId);
192 $this->threadStrategy->fillThreads();
195 $this->threadStrategy->lockThread();
196 $threadId = $this->threadStrategy->getThreadId();
199 if (is_null($threadId))
201 if (!$this->threadStrategy->hasUnprocessedThreads())
204 $status = self::updateActualStatus(
209 $this->finalizePosting(
$status);
213 $this->resultCode = static::RESULT_CONTINUE;
217 if (static::lock($this->postingId, $threadId) ===
false)
220 throw new DB\Exception(
Loc::getMessage(
'SENDER_POSTING_MANAGER_ERR_LOCK'));
225 $this->resultCode = static::RESULT_CONTINUE;
227 static::unlock($this->postingId, $threadId);
234 $this->resultCode = static::RESULT_WAITING_RECIPIENT;
236 static::unlock($this->postingId, $threadId);
245 $this->resultCode = static::RESULT_SENT;
247 static::unlock($this->postingId, $threadId);
254 AddMessage2Log(
'Status does not equal Part. PostingId: ' . $this->postingId,
'sender');
255 $this->resultCode = static::RESULT_ERROR;
257 static::unlock($this->postingId, $threadId);
263 $this->resultCode = static::RESULT_CONTINUE;
264 static::unlock($this->postingId, $threadId);
269 $threadRecipients = $this->threadStrategy->getRecipients($this->limit);
270 $recipients = static::getRecipientsToSend($threadRecipients);
271 if (($count = count($recipients))> 0)
273 $this->message->getTransport()->setSendCount($count);
274 if (!$this->message->getTransport()->start())
280 $this->sendToRecipients($recipients);
283 $this->message->getTransport()->end();
286 self::unlock($this->postingId, $threadId);
288 $status = self::updateActualStatus(
291 $this->threadStrategy->hasUnprocessedThreads()
295 $threadRecipients->getSelectedRowsCount() === 0 ?
300 $this->threadStrategy->updateStatus($threadStatus);
302 if ($threadId < $this->threadStrategy->lastThreadId())
304 $this->resultCode = static::RESULT_CONTINUE;
309 if ($this->threadStrategy->hasUnprocessedThreads())
311 $this->resultCode = static::RESULT_CONTINUE;
316 $this->finalizePosting(
$status);
326 public function load($postingId)
328 $postingDb = PostingTable::getList(
335 'MAILING_CHAIN_REITERATE' =>
'MAILING_CHAIN.REITERATE',
336 'MAILING_CHAIN_IS_TRIGGER' =>
'MAILING_CHAIN.IS_TRIGGER',
341 '=MAILING.ACTIVE' =>
'Y',
342 '=MAILING_CHAIN.STATUS' => [
343 Model\LetterTable::STATUS_SEND,
344 Model\LetterTable::STATUS_PLAN,
349 if ($postingData = $postingDb->fetch())
351 $this->postingId = $postingData[
'ID'];
352 $this->status = $postingData[
'STATUS'];
354 $this->mailingId = $postingData[
'MAILING_ID'];
355 $this->letterId = $postingData[
'MAILING_CHAIN_ID'];
356 $this->sendCount = $postingData[
'COUNT_SEND_ALL'];
358 $this->isReiterate = $postingData[
'MAILING_CHAIN_REITERATE'] ==
'Y';
359 $this->isTrigger = $postingData[
'MAILING_CHAIN_IS_TRIGGER'] ==
'Y';
404 if (!$this->postingId)
421 $onBeforeStartResult = $this->message->onBeforeStart();
422 if ($onBeforeStartResult->isSuccess())
425 Model\PostingTable::update($this->postingId, [
'STATUS' => $this->status]);
429 static::updateActualStatus($this->postingId,
true);
432 $errorMessage = implode(
', ', $onBeforeStartResult->getErrorMessages());
433 if($errorMessage <>
'')
435 Model\LetterTable::update($this->letterId, [
'ERROR_MESSAGE' => $errorMessage]);
472 elseif (!$hasStatusNone && !$awaitThread && !$hasStatusWait)
481 $postingUpdateFields = [
484 'COUNT_SEND_ALL' => 0
488 foreach ($recipientStatusToPostingFieldMap as $recipientStatus => $postingFieldName)
490 if (!array_key_exists($recipientStatus, $statusList))
492 $statusList[$recipientStatus] = 0;
494 $postingUpdateFields[$postingFieldName] = $statusList[$recipientStatus];
496 $postingUpdateFields[
'COUNT_SEND_ALL'] = array_sum($statusList);
497 Model\PostingTable::update(
$postingId, $postingUpdateFields);
688 self::applyRecipientToMessage($this->message, $recipient);
692 'FIELDS' => $this->message->getFields(),
693 'TRACK_READ' => $this->message->getReadTracker()->getArray(),
694 'TRACK_CLICK' => $this->message->getClickTracker()->getArray(),
695 'MAILING_CHAIN_ID' => $this->letter->getId()
697 $linkDomain = $this->message->getReadTracker()->getLinkDomain();
700 $eventSendParams[
'LINK_DOMAIN'] = $linkDomain;
702 $event =
new Main\Event(
'sender',
'OnBeforePostingSendRecipient', [$eventSendParams]);
704 foreach ($event->getResults() as $eventResult)
706 if ($eventResult->getType() == Main\EventResult::ERROR)
711 if (is_array($eventResult->getParameters()))
713 $eventSendParams = array_merge($eventSendParams, $eventResult->getParameters());
716 if (count($event->getResults()) > 0)
718 $this->message->setFields($eventSendParams[
'FIELDS']);
719 $this->message->getReadTracker()->setArray($eventSendParams[
'TRACK_READ']);
720 $this->message->getReadTracker()->setArray($eventSendParams[
'TRACK_CLICK']);
725 $sendResult = $this->message->send();