- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_external_sale_import.php
- Класс: \CCrmExternalSaleImport
- Вызов: CCrmExternalSaleImport::SaveOrderDataContactBP
private function SaveOrderDataContactBP($contactId, $isNewContact, $arParameters = array())
{
$contactId = intval($contactId);
if ($contactId <= 0)
return;
self::AddTrace('SAVE_ORDER_CONTACT_BP:START');
static $isBPIncluded = null;
if ($isBPIncluded === null)
$isBPIncluded = CModule::IncludeModule("bizproc") && CBPRuntime::isFeatureEnabled();
if (!$isBPIncluded)
return;
static $arBPTemplates = [];
$autoExecType = $isNewContact ? CBPDocumentEventType::Create : CBPDocumentEventType::Edit;
if (!array_key_exists($autoExecType, $arBPTemplates))
{
$arBPTemplates[$autoExecType] = CBPWorkflowTemplateLoader::SearchTemplatesByDocumentType(
array('crm', 'CCrmDocumentContact', 'CONTACT'),
$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', 'CCrmDocumentContact', 'CONTACT_' . $contactId),
$arParameters
);
$wi->Start();
}
catch (Exception $e)
{
$this->AddError($e->getCode(), $e->getMessage());
}
}
}
self::AddTrace('SAVE_ORDER_CONTACT_BP:FINISED');
}