35 $this->fillDocuments();
36 $documents = clone($this->getDocuments());
39 foreach ($documents as $document)
41 $this->removeFromDocuments($document);
52 $this->terminateWorkflows();
55 if (
$result->isSuccess() && $this->isFixed())
57 $documentService = \CBPRuntime::GetRuntime(
true)->getDocumentService();
59 $documentService->onDebugSessionDocumentStatusChanged(
61 $this->getStartedBy(),
82 $this->killWorkflows();
89 foreach ($this->getDocuments() as $document)
91 $deletionResult = $document->delete();
93 if (!$deletionResult->isSuccess())
95 $result->addErrors($deletionResult->getErrors());
102 private function killWorkflows()
104 $workflowContexts = $this->getWorkflowContexts();
106 if ($workflowContexts)
108 foreach ($workflowContexts as
$context)
110 \CBPDocument::killWorkflow(
$context->getWorkflowId());
112 $shouldSaveTemplateShards = (bool)DebuggerSessionWorkflowContextTable::getList([
115 'TEMPLATE_SHARDS_ID' =>
$context->getTemplateShardsId(),
120 if (!$shouldSaveTemplateShards)
122 $shards =
$context->fillTemplateShards();
134 private function terminateWorkflows(): Result
136 $workflowContexts = $this->getWorkflowContexts();
139 if ($workflowContexts)
141 foreach ($workflowContexts as
$context)
143 \CBPDocument::TerminateWorkflow(
$context->getWorkflowId(),
null,
$errors);
148 $rawError[
'message'],
150 [
'workflowId' =>
$context->getWorkflowId()]
164 $result = new \Bitrix\Main\Result();
165 $error = static::getErrorByCode(self::ERROR_DOCUMENT_ID_ALREADY_FIXED);
173 ->setSessionId($this->getId())
174 ->setDocumentId($documentId)
179 $document->setDateExpire(
null);
182 $this->addToDocuments($document);
187 $documentService = \CBPRuntime::GetRuntime(
true)->getDocumentService();
189 $parameterDocumentId[2] = $documentId;
191 $documentService->onDebugSessionDocumentStatusChanged(
192 $parameterDocumentId,
193 $this->getStartedBy(),
203 $documentId = $debuggerSessionDocument->getDocumentId();
205 $parameterDocumentId[2] = $documentId;
207 parent::removeFromDocuments($debuggerSessionDocument);
208 $debuggerSessionDocument->delete();
210 $documentService = \CBPRuntime::GetRuntime(
true)->getDocumentService();
212 $documentService->onDebugSessionDocumentStatusChanged(
213 $parameterDocumentId,
214 $this->getStartedBy(),
220 $target->setDocumentId($documentId);
222 $target->getRuntime()->runDocumentStatus();
234 $contextRow = DebuggerSessionWorkflowContextTable::getRow([
235 'filter' => [
'WORKFLOW_ID' => $workflowId],
238 $context = DebuggerSessionWorkflowContextTable::wakeUpObject($contextRow);
242 $context = DebuggerSessionWorkflowContextTable::createObject();
244 ->setWorkflowId($workflowId)
245 ->setSessionId($this->getId())
254 $this->addToWorkflowContexts(
$context);
262 $ids = $this->getWorkflowContexts()->getWorkflowIdList();
264 return in_array($workflowId, $ids);
271 $result = new \Bitrix\Main\Result();
272 $error = static::getErrorByCode(self::ERROR_DOCUMENT_ID_ALREADY_FIXED);
280 $addDocumentResult = $this->
addDocument($documentId);
281 if ($addDocumentResult->isSuccess())
283 $this->setFixed(
true);
288 $documentService = \CBPRuntime::GetRuntime(
true)->getDocumentService();
290 $documentService->onDebugSessionDocumentStatusChanged(
292 $this->getStartedBy(),
300 return $addDocumentResult;
303 $documents = clone($this->getDocuments());
304 $documentIds = $documents ? $documents->getDocumentIdList() : [];
306 if (!in_array($documentId, $documentIds,
true))
308 $result = new \Bitrix\Main\Result();
309 $error = static::getErrorByCode(self::ERROR_UNKNOWN_DOCUMENT_ID);
313 'documentId' => $documentId,
319 foreach ($documents as $document)
321 if ($document->getDocumentId() === $documentId)
323 $this->setFixed(
true);
328 $this->removeFromDocuments($document);
334 $documentService = \CBPRuntime::GetRuntime(
true)->getDocumentService();
336 $documentService->onDebugSessionDocumentStatusChanged(
338 $this->getStartedBy(),
348 return $this->getActive();
353 return $this->getFixed();
359 $this->getModuleId(),
361 $this->getDocumentType(),
369 $document = $this->getDocuments()->getAll()[0];
372 $document->setSession($this);
383 return $userId === $this->getStartedBy();
388 [
$moduleId,
$entity, $documentType] = \CBPHelper::ParseDocumentId($parameterDocumentType);
392 &&
$entity === $this->getEntity()
393 && $documentType === $this->getDocumentType()
399 $documents = $this->getDocuments();
405 foreach ($documents as $document)
407 $document->setSession($this);
408 if ($parameterDocumentId === $document->getParameterDocumentId())
424 return \Bitrix\Main\Localization\Loc::getMessage(
425 'BIZPROC_DEBUGGER_SESSION_SESSION_SHORT_DESCRIPTION',
427 '#USER#' => $this->getStartedByPrintable(),
428 '#ENTITY#' => $this->getDocumentTypeCaption(),
435 return \Bitrix\Main\Localization\Loc::getMessage(
436 'BIZPROC_DEBUGGER_SESSION_SESSION_DESCRIPTION',
438 '#USER#' => $this->getStartedByPrintable(),
439 '#ENTITY#' => $this->getDocumentTypeCaption(),
440 '#DATE#' => $this->getStartedDate()->toUserTime(),
480 private function getStartedByPrintable(): string
482 $format = \CSite::GetNameFormat(
false);
483 $user = \CUser::GetList(
486 [
'ID' => $this->getStartedBy()],
502 return $user ? \CUser::FormatName($format,
$user,
true,
false) :
'';
505 private function getDocumentTypeCaption()
507 $runtime = \CBPRuntime::GetRuntime();
508 $runtime->StartRuntime();
509 $documentService = $runtime->GetService(
'DocumentService');
518 $this->fillDocuments();
519 $sessionDocuments = $this->getDocuments() ?? [];
520 foreach ($sessionDocuments as $document)
522 $document->setSession($this);
523 $documents[] = $document->toArray();
527 'Id' => $this->getId(),
528 'Mode' => $this->getMode(),
529 'StartedBy' => $this->getStartedBy(),
530 'Active' => $this->getActive(),
531 'Fixed' => $this->getFixed(),
532 'Documents' => $documents,
534 'CategoryId' => $this->getDocumentCategoryId(),
544 foreach ($this->getWorkflowContexts() as
$context)
546 $workflowIds[] =
$context->getWorkflowId();
551 '@WORKFLOW_ID' => $workflowIds,
554 ])->fetchCollection()->getAll();
559 $workflowRobots = [];
560 $this->getWorkflowContexts()->fillTemplateShards();
561 foreach ($this->getWorkflowContexts() as
$context)
563 $workflowId =
$context->getWorkflowId();
564 $templateShards =
$context->getTemplateShards();
566 $workflowRobots[$workflowId] = $templateShards ? $templateShards->getRobotData() : [];
569 return $workflowRobots;
574 if (
$code === static::ERROR_DOCUMENT_ID_ALREADY_FIXED)
576 return new \Bitrix\Main\Error(
577 Loc::getMessage(
'BIZPROC_DEBUGGER_SESSION_ERROR_DOCUMENT_ID_ALREADY_FIXED'),
578 self::ERROR_DOCUMENT_ID_ALREADY_FIXED
582 if (
$code === static::ERROR_UNKNOWN_DOCUMENT_ID)
584 return new \Bitrix\Main\Error(
585 Loc::getMessage(
'BIZPROC_DEBUGGER_SESSION_ERROR_UNKNOWN_DOCUMENT_ID_1'),
586 self::ERROR_UNKNOWN_DOCUMENT_ID
static getList(array $parameters=array())
static createObject($setDefaultValues=true)