CCrmExternalSaleImport::SaveOrderDataCompanyBP

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

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

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

	static $arBPTemplates = [];
	$autoExecType = $isNewCompany ? CBPDocumentEventType::Create : CBPDocumentEventType::Edit;
	if (!array_key_exists($autoExecType, $arBPTemplates))
	{
		$arBPTemplates[$autoExecType] = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType(
			array('crm', 'CCrmDocumentCompany', 'COMPANY'),
			$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', 'CCrmDocumentCompany', 'COMPANY_' . $companyId),
					$arParameters
				);
				$wi->Start();
			}
			catch (Exception $e)
			{
				$this->AddError($e->getCode(), $e->getMessage());
			}
		}
	}

	self::AddTrace('SAVE_ORDER_COMPANY_BP:FINISHED');
}

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