95 protected function runTemplates($documentStatus,
string $preGeneratedWorkflowId =
null)
101 if ($template->getId() > 0)
104 $trigger = $this->
getTarget()->getAppliedTrigger();
105 $this->
getTarget()->setAppliedTrigger([]);
108 !$template->isExternalModified()
111 && !$template->getRobots()
117 $documentType = $this->
getTarget()->getDocumentType();
118 $documentId = $this->
getTarget()->getDocumentId();
119 $documentComplexId = [$documentType[0], $documentType[1], $documentId];
122 \CBPDocument::PARAM_TAGRET_USER =>
null,
123 \CBPDocument::PARAM_USE_FORCED_TRACKING => $isDebug || !$template->isExternalModified(),
124 \CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT =>
true,
125 \CBPDocument::PARAM_DOCUMENT_TYPE => $documentType,
126 \CBPDocument::PARAM_DOCUMENT_EVENT_TYPE =>
127 $isDebug ? \CBPDocumentEventType::Debug : \CBPDocumentEventType::Automation,
128 \CBPDocument::PARAM_PRE_GENERATED_WORKFLOW_ID => $preGeneratedWorkflowId ??
null,
131 if (isset($trigger[
'RETURN']) && is_array($trigger[
'RETURN']))
133 $startParameters += $trigger[
'RETURN'];
136 foreach ($template->getParameters() as $parameterId => $parameter)
138 if (!isset($startParameters[$parameterId]) && isset($parameter[
'Default']))
140 $startParameters[$parameterId] = $parameter[
'Default'];
144 $this->setStarted($documentType[2], $documentId, $documentStatus);
146 $args = [$template->getId(), $documentComplexId, $startParameters, $errors];
148 if ($isDebug && $preGeneratedWorkflowId)
150 $session = Bizproc\Debugger\Session\Manager::getActiveSession();
151 $session->addWorkflowContext($preGeneratedWorkflowId, $template);
154 $workflowId = $isDebug
155 ? \CBPDocument::startDebugWorkflow(...$args)
156 : \CBPDocument::startWorkflow(...$args)
159 if (!$errors && $workflowId)
174 $trackingService = \CBPRuntime::getRuntime(
true)->getTrackingService();
176 $trackingService->write(
178 \CBPTrackingType::Trigger,
180 \CBPActivityExecutionStatus::Closed,
181 \CBPActivityExecutionResult::Succeeded,
189 $analyticsService = \CBPRuntime::getRuntime(
true)->getAnalyticsService();
190 if ($analyticsService->isEnabled())
192 $analyticsService->write($documentId,
'trigger_run', $trigger[
'CODE']);
221 $preGeneratedWorkflowId = \CBPRuntime::generateWorkflowId();
222 $isManualAdd = $context && $context->isManualOperation();
224 if (!$isManualAdd && $this->
isDebug(
true))
226 $debugSession = Bizproc\Debugger\Session\Manager::getActiveSession();
228 if ($debugSession->isBeforeDebuggerStartState())
230 $debugSession->addDocument($this->
getTarget()->getDocumentId());
235 $debugSession->addWorkflowContext($preGeneratedWorkflowId, []);
237 $status = $this->
getTarget()->getDocumentStatus();
238 $this->writeSessionLegendTrack($preGeneratedWorkflowId);
239 $this->writeStatusTracking($preGeneratedWorkflowId, $status);
240 $this->writeCategoryTracking($preGeneratedWorkflowId);
254 $preGeneratedWorkflowId = \CBPRuntime::generateWorkflowId();
257 $debugSession = Bizproc\Debugger\Session\Manager::getActiveSession();
259 if ($debugSession->isBeforeDebuggerStartState())
264 $debugSession->addWorkflowContext($preGeneratedWorkflowId, []);
266 $status = $this->
getTarget()->getDocumentStatus();
267 $documentType = $this->
getTarget()->getDocumentType()[2];
268 $documentId = $this->
getTarget()->getDocumentId();
269 if (!$this->isStarted($documentType, $documentId, $status))
294 protected function isDebug(
bool $isOnDocumentAdd =
false): bool
296 $debugSession = Bizproc\Debugger\Session\Manager::getActiveSession();
302 $documentType = $this->
getTarget()->getDocumentType();
303 if (!$debugSession->isStartedInDocumentType($documentType))
308 $documentId = $this->
getTarget()->getComplexDocumentId();
309 if (!$isOnDocumentAdd || $debugSession->isExperimentalMode() || $debugSession->isFixed())
311 return $debugSession->isSessionDocument($documentId);
314 $documentCategoryId = $this->
getTarget()->getDocumentCategory();
316 return $documentCategoryId === $debugSession->getDocumentCategoryId();
323 $trigger = $this->
getTarget()->getAppliedTrigger();
326 $trigger[
'APPLIED_RULE_LOG'] = $this->
getTarget()->getAppliedTriggerConditionResults();
327 $this->writeAppliedTriggerTrack($workflowId, $trigger);
330 $this->writeStatusTracking($workflowId, $status);
333 Bizproc\Debugger\Listener::getInstance()->onDocumentStatusChanged($status);
348 if ($this->
isDebug() && $changes)
350 $debugSession = Bizproc\Debugger\Session\Manager::getActiveSession();
351 if ($debugSession->isBeforeDebuggerStartState())
358 if (
$target->getDocumentCategoryCode() && in_array(
$target->getDocumentCategoryCode(), $changes))
360 $session = Bizproc\Debugger\Session\Manager::getActiveSession();
361 $sessionWorkflows = $session->getWorkflowContexts()->getWorkflowIdList();
362 if (!empty($sessionWorkflows))
364 $lastWorkflowId = $sessionWorkflows[array_key_last($sessionWorkflows)];
365 $this->writeCategoryTracking($lastWorkflowId);
369 Bizproc\Debugger\Listener::getInstance()->onDocumentUpdated($changes);