- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/timeline/bizproccontroller.php
- Класс: Bitrix\Crm\Timeline\BizprocController
- Вызов: BizprocController::onWorkflowStatusChange
public function onWorkflowStatusChange($workflowId, $status)
{
if (!$workflowId)
{
throw new Main\ArgumentException('Workflow ID is empty.', 'workflowId');
}
if ($status !== \CBPWorkflowStatus::Created
&& $status !== \CBPWorkflowStatus::Completed
&& $status !== \CBPWorkflowStatus::Terminated
)
{
return;
}
$fields = \CBPStateService::getWorkflowStateInfo($workflowId);
if (!is_array($fields))
{
return;
}
[$entityTypeName, $entityId] = explode('_', $fields['DOCUMENT_ID'][2]);
$entityTypeId = \CCrmOwnerType::ResolveID($entityTypeName);
$historyEntryID = BizprocEntry::create(
[
'AUTHOR_ID' => self::resolveCreatorID($fields),
'SETTINGS' => [
'WORKFLOW_ID' => $fields['ID'],
'WORKFLOW_TEMPLATE_ID' => $fields['WORKFLOW_TEMPLATE_ID'],
'WORKFLOW_TEMPLATE_NAME' => $fields['WORKFLOW_TEMPLATE_NAME'],
'WORKFLOW_STATUS' => $status,
'WORKFLOW_STATUS_NAME' => \CBPWorkflowStatus::Out($status),
],
'BINDINGS' => [
[
'ENTITY_TYPE_ID' => $entityTypeId,
'ENTITY_ID' => $entityId,
],
],
]
);
$enableHistoryPush = $historyEntryID > 0;
if ($enableHistoryPush && Main\Loader::includeModule('pull'))
{
$pushParams = [];
if ($enableHistoryPush)
{
$historyFields = TimelineEntry::getByID($historyEntryID);
if (is_array($historyFields))
{
$pushParams['HISTORY_ITEM'] = $this->prepareHistoryDataModel(
$historyFields,
['ENABLE_USER_INFO' => true]
);
}
}
$tag = TimelineEntry::prepareEntityPushTag($entityTypeId, $entityId);
\CPullWatch::AddToStack(
$tag,
[
'module_id' => 'crm',
'command' => 'timeline_bizproc_status',
'params' => array_merge($pushParams, ['TAG' => $tag]),
]
);
}
}