47 $documentType = $this->
getTarget()->getDocumentType();
48 $documentId = $this->
getTarget()->getDocumentId();
49 $ids = WorkflowInstanceTable::getList([
52 '=MODULE_ID' => $documentType[0],
53 '=ENTITY' => $documentType[1],
54 '=DOCUMENT_ID' => $documentId,
56 '=TEMPLATE.DOCUMENT_TYPE' => $documentType[2],
59 $workflowInstanceIds = array_column($ids,
'ID');
61 $runtime = \CBPRuntime::getRuntime();
62 $workflows = $runtime->getWorkflows();
63 $workflowsRuntimeIds = [];
64 foreach ($workflows as $id => $workflow)
66 $eventType = $workflow->getRootActivity()->getDocumentEventType();
69 && \CBPHelper::isEqualDocument($workflow->getDocumentType(), $documentType)
70 && \CBPHelper::isEqualDocument($workflow->getDocumentId(), $this->getTarget()->getComplexDocumentId())
73 $workflowsRuntimeIds[] = $id;
77 return array_merge($workflowInstanceIds, $workflowsRuntimeIds);
115 protected function runTemplates($documentStatus,
string $preGeneratedWorkflowId =
null)
124 $trigger = $this->
getTarget()->getAppliedTrigger();
125 $this->
getTarget()->setAppliedTrigger([]);
137 $documentType = $this->
getTarget()->getDocumentType();
138 $documentId = $this->
getTarget()->getDocumentId();
139 $documentComplexId = [$documentType[0], $documentType[1], $documentId];
140 $useForcedTracking = $this->canUseForcedTracking() && !
$template->isExternalModified();
143 \CBPDocument::PARAM_TAGRET_USER =>
null,
144 \CBPDocument::PARAM_USE_FORCED_TRACKING => $isDebug || $useForcedTracking,
145 \CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT =>
true,
146 \CBPDocument::PARAM_DOCUMENT_TYPE => $documentType,
147 \CBPDocument::PARAM_DOCUMENT_EVENT_TYPE =>
149 \CBPDocument::PARAM_PRE_GENERATED_WORKFLOW_ID => $preGeneratedWorkflowId ??
null,
152 if (isset($trigger[
'RETURN']) && is_array($trigger[
'RETURN']))
154 $startParameters += $trigger[
'RETURN'];
157 foreach (
$template->getParameters() as $parameterId => $parameter)
159 if (!isset($startParameters[$parameterId]) && isset($parameter[
'Default']))
161 $startParameters[$parameterId] = $parameter[
'Default'];
165 $this->setStarted($documentType[2], $documentId, $documentStatus);
167 $args = [
$template->getId(), $documentComplexId, $startParameters,
$errors];
169 if ($isDebug && $preGeneratedWorkflowId)
172 $session->addWorkflowContext($preGeneratedWorkflowId,
$template);
175 $workflowId = $isDebug
176 ? \CBPDocument::startDebugWorkflow(...$args)
177 : \CBPDocument::startWorkflow(...$args)
187 if ($useForcedTracking && !$isDebug)
189 $this->clearOldTrack($documentComplexId,
$template->getId(), $workflowId);
237 $preGeneratedWorkflowId = \CBPRuntime::generateWorkflowId();
240 if (!$isManualAdd && $this->
isDebug(
true))
244 if ($debugSession->isBeforeDebuggerStartState())
246 $debugSession->addDocument($this->
getTarget()->getDocumentId());
251 $debugSession->addWorkflowContext($preGeneratedWorkflowId, []);
254 $this->writeSessionLegendTrack($preGeneratedWorkflowId);
255 $this->writeStatusTracking($preGeneratedWorkflowId,
$status);
256 $this->writeCategoryTracking($preGeneratedWorkflowId);
270 $preGeneratedWorkflowId = \CBPRuntime::generateWorkflowId();
275 if ($debugSession->isBeforeDebuggerStartState())
280 $debugSession->addWorkflowContext($preGeneratedWorkflowId, []);
283 $documentType = $this->
getTarget()->getDocumentType()[2];
284 $documentId = $this->
getTarget()->getDocumentId();
285 if (!$this->isStarted($documentType, $documentId,
$status))
310 protected function isDebug(
bool $isOnDocumentAdd =
false): bool
318 $documentType = $this->
getTarget()->getDocumentType();
319 if (!$debugSession->isStartedInDocumentType($documentType))
324 $documentId = $this->
getTarget()->getComplexDocumentId();
325 if (!$isOnDocumentAdd || $debugSession->isExperimentalMode() || $debugSession->isFixed())
327 return $debugSession->isSessionDocument($documentId);
330 $documentCategoryId = $this->
getTarget()->getDocumentCategory();
332 return $documentCategoryId === $debugSession->getDocumentCategoryId();
364 if ($this->
isDebug() && $changes)
367 if ($debugSession->isBeforeDebuggerStartState())
374 if (
$target->getDocumentCategoryCode() && in_array(
$target->getDocumentCategoryCode(), $changes))
377 $sessionWorkflows = $session->getWorkflowContexts()->getWorkflowIdList();
378 if (!empty($sessionWorkflows))
380 $lastWorkflowId = $sessionWorkflows[array_key_last($sessionWorkflows)];
381 $this->writeCategoryTracking($lastWorkflowId);