- Модуль: bizproc
- Путь к файлу: ~/bitrix/modules/bizproc/lib/automation/engine/runtime.php
- Класс: BitrixBizprocAutomationEngineRuntime
- Вызов: Runtime::runTemplates
protected function runTemplates($documentStatus, string $preGeneratedWorkflowId = null)
{
$isDebug = $this->isDebug();
$template = new Template($this->getTarget()->getDocumentType(), $documentStatus);
$workflowId = null;
if ($template->getId() > 0)
{
$errors = [];
$trigger = $this->getTarget()->getAppliedTrigger();
$this->getTarget()->setAppliedTrigger([]);
if (
!$template->isExternalModified()
&& !$isDebug
&& !$trigger
&& !$template->getRobots()
)
{
return false;
}
$documentType = $this->getTarget()->getDocumentType();
$documentId = $this->getTarget()->getDocumentId();
$documentComplexId = [$documentType[0], $documentType[1], $documentId];
$startParameters = [
CBPDocument::PARAM_TAGRET_USER => null, //Started by System
CBPDocument::PARAM_USE_FORCED_TRACKING => $isDebug || !$template->isExternalModified(),
CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT => true,
CBPDocument::PARAM_DOCUMENT_TYPE => $documentType,
CBPDocument::PARAM_DOCUMENT_EVENT_TYPE =>
$isDebug ? CBPDocumentEventType::Debug : CBPDocumentEventType::Automation,
CBPDocument::PARAM_PRE_GENERATED_WORKFLOW_ID => $preGeneratedWorkflowId ?? null,
];
if (isset($trigger['RETURN']) && is_array($trigger['RETURN']))
{
$startParameters += $trigger['RETURN'];
}
foreach ($template->getParameters() as $parameterId => $parameter)
{
if (!isset($startParameters[$parameterId]) && isset($parameter['Default']))
{
$startParameters[$parameterId] = $parameter['Default'];
}
}
$this->setStarted($documentType[2], $documentId, $documentStatus);
$args = [$template->getId(), $documentComplexId, $startParameters, $errors];
if ($isDebug)
{
$session = BizprocDebuggerSessionManager::getActiveSession();
$session->addWorkflowContext($preGeneratedWorkflowId, $template);
}
$workflowId = $isDebug
? CBPDocument::startDebugWorkflow(...$args)
: CBPDocument::startWorkflow(...$args)
;
if (!$errors && $workflowId)
{
if ($trigger)
{
$this->writeTriggerTracking($workflowId, $trigger);
$this->writeTriggerAnalytics($documentComplexId, $trigger);
}
}
}
return $workflowId;
}