Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
WriterDebugTrack.php
1<?php
2
4
5trait WriterDebugTrack
6{
7 protected function writeDebugTrack(
8 string $workflowId,
9 string $name,
10 int $status,
11 int $result,
12 string $title = '',
13 $toWrite = [],
14 int $trackType = \CBPTrackingType::Debug
15 ): ?int
16 {
18 $trackingService = \CBPRuntime::GetRuntime(true)->getDebugService('TrackingService');
19 if ($trackingService && $trackingService->canWrite($trackType, $workflowId))
20 {
21 return $trackingService->write($workflowId, $trackType, $name, $status, $result, $title, $toWrite);
22 }
23
24 return null;
25 }
26
27 protected function preparePropertyForWritingToTrack($value, string $name = ''): array
28 {
29 $toWrite = [];
30 if ($name)
31 {
32 $toWrite['propertyName'] = $name;
33 }
34
35 $toWrite['propertyValue'] = $value;
36
37 return $toWrite;
38 }
39
40 protected function writeSessionLegendTrack($workflowId): ?int
41 {
42 if (!$workflowId)
43 {
44 return null;
45 }
46
47 $debugSession = \Bitrix\Bizproc\Debugger\Session\Manager::getActiveSession();
48 if (!$debugSession)
49 {
50 return null;
51 }
52
53 return $this->writeDebugTrack(
54 $workflowId,
55 'SESSION_LEGEND',
56 \CBPActivityExecutionStatus::Closed,
57 \CBPActivityExecutionResult::Succeeded,
58 '',
59 $debugSession->getShortDescription()
60 );
61 }
62
63 protected function writeDocumentStatusTrack($workflowId, array $status): ?int
64 {
65 if (!$workflowId)
66 {
67 return null;
68 }
69
70 $statusLog = [
71 'STATUS_ID' => $status['STATUS_ID'],
72 'NAME' => $status['NAME'],
73 'COLOR' => $status['COLOR'],
74 ];
75
76 return $this->writeDebugTrack(
77 $workflowId,
78 'STATUS_CHANGED',
79 \CBPActivityExecutionStatus::Closed,
80 \CBPActivityExecutionResult::Succeeded,
81 '',
82 $statusLog,
83 \CBPTrackingType::DebugAutomation
84 );
85 }
86
87 protected function writeAppliedTriggerTrack($workflowId, array $trigger): ?int
88 {
89 if (!$workflowId)
90 {
91 return null;
92 }
93
94 return $this->writeDebugTrack(
95 $workflowId,
96 'TRIGGER_LOG',
97 \CBPActivityExecutionStatus::Closed,
98 \CBPActivityExecutionResult::Succeeded,
99 $trigger['NAME'],
100 $trigger['APPLIED_RULE_LOG'] ?? [],
101 \CBPTrackingType::DebugAutomation
102 );
103 }
104
105 protected function writeDocumentCategoryTrack($workflowId, $categoryName): ?int
106 {
107 if (!$workflowId)
108 {
109 return null;
110 }
111
112 return $this->writeDebugTrack(
113 $workflowId,
114 'CATEGORY_CHANGED',
115 \CBPActivityExecutionStatus::Closed,
116 \CBPActivityExecutionResult::Succeeded,
117 '',
118 $categoryName,
119 \CBPTrackingType::DebugAutomation
120 );
121 }
122}