EventHandler::onMailEventMailChangeStatus

  1. Bitrix24 API (v. 23.675.0)
  2. sender
  3. EventHandler
  4. onMailEventMailChangeStatus
  • Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/integration/eventhandler.php
  • Класс: Bitrix\Sender\Integration\EventHandler
  • Вызов: EventHandler::onMailEventMailChangeStatus
static function onMailEventMailChangeStatus($result)
{
	if (!$result->isBelongTo('sender', 'rcpt'))
	{
		return;
	}

	// return if status already updated
	$row = PostingRecipientTable::getRow([
		'select' => [
			'STATUS', 'POSTING_ID', 'CONTACT_ID',
			'CONTACT_IS_SEND_SUCCESS' => 'CONTACT.IS_SEND_SUCCESS'
		],
		'filter' => ['=ID' => $result->getEntityId()]
	]);
	if (!$row)
	{
		return;
	}

	if (!$result->isError())
	{
		// update contact send_success flag
		if ($row['CONTACT_IS_SEND_SUCCESS'] !== 'Y')
		{
			ContactTable::update($row['CONTACT_ID'], ['IS_SEND_SUCCESS' => 'Y']);
		}
	}
	elseif ($result->isPermanentError())
	{
		// return if status already updated
		if ($row['STATUS'] === PostingRecipientTable::SEND_RESULT_ERROR)
		{
			return;
		}

		// update recipient status
		Model\Posting\RecipientTable::update(
			$result->getEntityId(),
			['STATUS' => PostingRecipientTable::SEND_RESULT_ERROR]
		);

		// update posting counters
		Model\PostingTable::update(
			$row['POSTING_ID'],
			[
				'COUNT_SEND_ERROR' => new Main\DB\SqlExpression('?# + 1', 'COUNT_SEND_ERROR'),
				'COUNT_SEND_SUCCESS' => new Main\DB\SqlExpression('?# - 1', 'COUNT_SEND_SUCCESS')
			]
		);

		// update daily limit counters
		if (Bitrix24\Service::isCloud())
		{
			Bitrix24\Limitation\DailyLimit::incrementError();
		}
	}
}

Добавить комментарий