<?php
// Bitrix\Bizproc\Automation\Engine\Runtime :: runTemplates()
// /dist/bitrix/modules/bizproc/lib/automation/engine/runtime.php:54
protected function runTemplates($documentStatus)
{
$template = new Template($this->getTarget()->getDocumentType(), $documentStatus);
if ($template->getId() > 0)
{
$errors = array();
$trigger = $this->getTarget()->getAppliedTrigger();
if (!$template->isExternalModified() && !$trigger && !$template->getRobots())
{
return false;
}
$documentType = $this->getTarget()->getDocumentType();
$documentId = $this->getTarget()->getDocumentId();
$documentComplexId = [$documentType[0], $documentType[1], $documentId];
$this->setStarted($documentType[2], $documentId, $documentStatus);
$workflowId = \CBPDocument::startWorkflow(
$template->getId(),
$documentComplexId,
array(
\CBPDocument::PARAM_TAGRET_USER => null, //Started by System
\CBPDocument::PARAM_USE_FORCED_TRACKING => !$template->isExternalModified(),
\CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT => true,
\CBPDocument::PARAM_DOCUMENT_TYPE => $documentType,
\CBPDocument::PARAM_DOCUMENT_EVENT_TYPE => \CBPDocumentEventType::Automation,
),
$errors
);
if (!$errors && $workflowId)
{
if ($trigger)
{
$this->writeTriggerTracking($workflowId, $trigger);
}
//not today
//$this->writeAnalytics($documentComplexId, $documentStatus, $trigger);
}
}
return true;
}