• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/mailingchain.php
  • Класс: BitrixSenderMailingChainTable
  • Вызов: MailingChainTable::initPosting
static function initPosting(?int $mailingChainId): ?int
{
	$postingId = null;
	$chainPrimary = array('ID' => $mailingChainId);
	$mailingChain = static::getRowById($chainPrimary);
	
	if(!$mailingChain)
	{
		return null;
	}

	$needAddPosting = true;
	if(!empty($mailingChain['POSTING_ID']))
	{
		$posting = PostingTable::getRowById(array('ID' => $mailingChain['POSTING_ID']));
		if($posting)
		{
			if($posting['STATUS'] == PostingTable::STATUS_NEW)
			{
				$postingId = $mailingChain['POSTING_ID'];
				$needAddPosting = false;
			}
			/*
			elseif($arMailingChain['IS_TRIGGER'] == 'Y')
			{
				$postingId = $arMailingChain['POSTING_ID'];
				$needAddPosting = false;
			}
			*/
		}
	}

	if($needAddPosting)
	{
		$consentSupported = false;
		try
		{
			$consentSupported = TransportAdapter::create($mailingChain['MESSAGE_CODE'])->isConsentSupported();
		}
		catch (ArgumentException $e)
		{
		}

		$postingAddDb = PostingTable::add(array(
			'MAILING_ID' => $mailingChain['MAILING_ID'],
			'MAILING_CHAIN_ID' => $mailingChain['ID'],
			'CONSENT_SUPPORT' => $consentSupported
		));
		if ($postingAddDb->isSuccess())
		{
			$postingId = $postingAddDb->getId();
			ModelLetterTable::update($mailingChainId, ['POSTING_ID' => $postingId]);
		}
	}

	if($postingId && $mailingChain['IS_TRIGGER'] != 'Y')
	{
		if(!PostingTable::initGroupRecipients($postingId, true))
		{
			ModelLetterTable::update($mailingChainId, ['WAITING_RECIPIENT' => 'Y']);
		}
	}

	return $postingId;
}