CCrmExternalSaleImport::SaveOrderDataDealBP

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmExternalSaleImport
  4. SaveOrderDataDealBP
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_external_sale_import.php
  • Класс: \CCrmExternalSaleImport
  • Вызов: CCrmExternalSaleImport::SaveOrderDataDealBP
private function SaveOrderDataDealBP($dealId, $isNewDeal, $arParameters = array())
{
	$dealId = intval($dealId);
	if ($dealId <= 0)
		return;

	self::AddTrace('SAVE_ORDER_DEAL_BP:START');

	static $isBPIncluded = null;
	if ($isBPIncluded === null)
		$isBPIncluded = CModule::IncludeModule("bizproc") && CBPRuntime::isFeatureEnabled();
	if (!$isBPIncluded)
		return;

	static $arBPTemplates = [];

	$autoExecType = $isNewDeal ? CBPDocumentEventType::Create : CBPDocumentEventType::Edit;
	if (!array_key_exists($autoExecType, $arBPTemplates))
	{
		$arBPTemplates[$autoExecType] = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType(
			array('crm', 'CCrmDocumentDeal', 'DEAL'),
			$autoExecType
		);
	}

	if (is_array($arBPTemplates[$autoExecType]))
	{
		if (!is_array($arParameters))
		{
			$arParameters = array($arParameters);
		}
		if (!array_key_exists("TargetUser", $arParameters))
		{
			$assignedById = intval(COption::GetOptionString("crm", "sale_deal_assigned_by_id", "0"));
			if ($assignedById > 0)
			{
				$arParameters["TargetUser"] = "user_" . $assignedById;
			}
		}

		$runtime = CBPRuntime::GetRuntime();

		foreach ($arBPTemplates[$autoExecType] as $wt)
		{
			try
			{
				$wi = $runtime->CreateWorkflow(
					$wt["ID"],
					array('crm', 'CCrmDocumentDeal', 'DEAL_' . $dealId),
					$arParameters
				);
				$wi->Start();
			}
			catch (Exception $e)
			{
				$this->AddError($e->getCode(), $e->getMessage());
			}
		}
	}
	if($isNewDeal)
	{
		$starter = new \Bitrix\Crm\Automation\Starter(\CCrmOwnerType::Deal, $dealId);
		$assignedById = intval(COption::GetOptionString("crm", "sale_deal_assigned_by_id", "0"));
		if ($assignedById > 0)
		{
			$starter->setUserId($assignedById);
		}

		$starter->setContextToImport()->runOnAdd();
	}

	self::AddTrace('SAVE_ORDER_DEAL_BP:FINISED');
}

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