Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
DebugWorkflow.php
1<?php
2
4
8use CBPActivityExecutorOperationType;
9use IBPActivityExternalEventListener;
10
11class DebugWorkflow extends \CBPWorkflow
12{
13 public function __construct($instanceId,\CBPRuntime $runtime)
14 {
15 parent::__construct($instanceId, $runtime);
16 $this->persister = Persister::GetPersister();
17 }
18
23 public function __sleep()
24 {
25 $this->toggleQueueExceptions();
26
27 return ['activitiesQueue', 'eventsQueue'];
28 }
29
30 public function __wakeup()
31 {
32 $this->toggleQueueExceptions();
33 }
34
35 private function toggleQueueExceptions()
36 {
37 foreach ($this->activitiesQueue as $index => $item)
38 {
39 if ($item[1] === CBPActivityExecutorOperationType::HandleFault && isset($item[2]))
40 {
41 if ($item[2] instanceof \Exception)
42 {
43 $this->activitiesQueue[$index][2] = [$item[2]->getMessage(), $item[2]->getCode()];
44 }
45 elseif (is_array($item[2]))
46 {
47 $this->activitiesQueue[$index][2] = new \Exception($item[2][0], $item[2][1]);
48 }
49 }
50 }
51 }
52
53 protected function setWorkflowStatus($newStatus)
54 {
55 parent::setWorkflowStatus($newStatus);
56 Listener::getInstance()->onWorkflowStatusChanged($this->getInstanceId(), $newStatus);
57 }
58
59 public function getDebugEventIds(): array
60 {
61 $ids = [];
62
63 foreach ($this->getEventsMap() as $id => $handlers)
64 {
65 foreach ($handlers as $handler)
66 {
67 if ($handler instanceof \IBPActivityDebugEventListener)
68 {
69 $ids[] = $id;
70 break;
71 }
72 }
73 }
74
75 return $ids;
76 }
77
78 public function addEventHandler($eventName, IBPActivityExternalEventListener $eventHandler)
79 {
80 parent::addEventHandler($eventName, $eventHandler);
81
82 if ($eventHandler instanceof \IBPActivityDebugEventListener)
83 {
84 Listener::getInstance()->onWorkflowEventAdded($this->getInstanceId(), $eventName);
85 }
86 }
87
88 public function removeEventHandler($eventName, IBPActivityExternalEventListener $eventHandler)
89 {
90 parent::removeEventHandler($eventName, $eventHandler);
91
92 if ($eventHandler instanceof \IBPActivityDebugEventListener)
93 {
94 Listener::getInstance()->onWorkflowEventRemoved($this->getInstanceId(), $eventName);
95 }
96 }
97
98 public function getService($name)
99 {
100 $service = $this->runtime->getDebugService($name);
101
102 if (is_null($service))
103 {
104 $service = $this->runtime->GetService($name);
105 }
106
107 return $service;
108 }
109
110 protected function runQueue()
111 {
112 $debuggerState = Manager::getDebuggerState();
113
114 if ($debuggerState->is(DebuggerState::NEXT_STEP))
115 {
116 $this->runStep();
117 }
118 elseif ($debuggerState->is(DebuggerState::RUN))
119 {
120 parent::runQueue();
121 }
122 }
123
124 public function sendDebugEvent($eventName, array $eventParameters = [])
125 {
126 $eventParameters['DebugEvent'] = true;
127
128 $this->sendExternalEvent($eventName, $eventParameters);
129 }
130
131 public function reload(\CBPActivity $rootActivity)
132 {
133 $this->activitiesQueue = $rootActivity->workflow->activitiesQueue;
134 $this->eventsQueue = $rootActivity->workflow->eventsQueue;
135
136 parent::reload($rootActivity);
137 }
138
139 public function isDebug(): bool
140 {
141 return true;
142 }
143}
addEventHandler($eventName, IBPActivityExternalEventListener $eventHandler)
__construct($instanceId,\CBPRuntime $runtime)
removeEventHandler($eventName, IBPActivityExternalEventListener $eventHandler)
sendDebugEvent($eventName, array $eventParameters=[])