• Модуль: messageservice
  • Путь к файлу: ~/bitrix/modules/messageservice/lib/Restriction/RestrictionManager.php
  • Класс: BitrixMessageServiceRestrictionRestrictionManager
  • Вызов: RestrictionManager::isCanSendMessage
public function isCanSendMessage(): bool
{
	if (empty($this->restrictions) || !self::canUse())
	{
		return true;
	}

	try
	{
		$this->lockRestrictions();

		$codes = array_keys($this->restrictions);
		$query = RestrictionTable::query()
			->setSelect([
				'CODE',
				'COUNTER',
				'ADDITIONAL_PARAMS'
			])
			->whereIn('CODE', $codes)
			->where('DATE_CREATE', new Date())
			->setLimit(count($this->restrictions))
		;

		foreach($query->exec() as $row)
		{
			$code = $row['CODE'];

			$this->restrictions[$code]
				->setCounter($row['COUNTER'])
				->setAdditionalParams($row['ADDITIONAL_PARAMS'])
			;
		}

		if (!$this->checkRestrictions())
		{
			return false;
		}

		$connection = Application::getConnection();
		$connection->startTransaction();

		foreach($this->restrictions as $restriction)
		{
			if (!$restriction->increase())
			{
				$this->notPassedRestriction = $restriction;
				$connection->rollbackTransaction();

				return false;
			}
		}
		$connection->commitTransaction();

		return true;
	}
	finally
	{
		$this->unlockRestrictions();
		if (isset($this->notPassedRestriction))
		{
			$this->notPassedRestriction->log();
		}
	}
}