• Модуль: mobile
  • Путь к файлу: ~/bitrix/modules/mobile/lib/Command.php
  • Класс: BitrixMobileCommand
  • Вызов: Command::transaction
protected function transaction(Closure $job): Result
{
	$db = Application::getConnection();

	$db->startTransaction();

	$result = $job();

	if (!$result instanceof Result)
	{
		$db->rollbackTransaction();
		$type = is_object($result) ? get_class($result) : gettype($result);
		throw new UnexpectedValueException("Return value must be instance of Bitrix\Main\Result, $type given");
	}

	if ($result->isSuccess())
	{
		$db->commitTransaction();
	}
	else
	{
		$db->rollbackTransaction();
	}

	return $result;
}