1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jabe\Impl\Pvm\Runtime\Operation; |
4
|
|
|
|
5
|
|
|
use Jabe\Delegate\ExecutionListenerInterface; |
6
|
|
|
use Jabe\Persistence\Entity\ExecutionEntity; |
7
|
|
|
use Jabe\Impl\Pvm\PvmActivityInterface; |
8
|
|
|
use Jabe\Impl\Pvm\Process\{ |
9
|
|
|
ActivityImpl, |
10
|
|
|
ScopeImpl |
11
|
|
|
}; |
12
|
|
|
use Jabe\Impl\Pvm\Runtime\{ |
13
|
|
|
CompensationBehavior, |
14
|
|
|
PvmExecutionImpl |
15
|
|
|
}; |
16
|
|
|
use Jabe\Impl\Core\Model\CoreModelElement; |
17
|
|
|
use Jabe\Impl\Core\Instance\CoreExecution; |
18
|
|
|
|
19
|
|
|
class PvmAtomicOperationDeleteCascadeFireActivityEnd extends PvmAtomicOperationActivityInstanceEnd |
20
|
|
|
{ |
21
|
|
|
protected function eventNotificationsStarted(CoreExecution $execution): CoreExecution |
22
|
|
|
{ |
23
|
|
|
$execution->setCanceled(true); |
24
|
|
|
return parent::eventNotificationsStarted($execution); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function getScope(CoreExecution $execution): CoreModelElement |
28
|
|
|
{ |
29
|
|
|
$activity = $execution->getActivity(); |
30
|
|
|
|
31
|
|
|
if ($activity !== null) { |
32
|
|
|
return $activity; |
33
|
|
|
} else { |
34
|
|
|
// TODO: when can this happen? |
35
|
|
|
$parent = $execution->getParent(); |
36
|
|
|
if ($parent !== null) { |
37
|
|
|
return $this->getScope($execution->getParent()); |
38
|
|
|
} |
39
|
|
|
return $execution->getProcessDefinition(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function getEventName(): string |
44
|
|
|
{ |
45
|
|
|
return ExecutionListenerInterface::EVENTNAME_END; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function eventNotificationsCompleted(CoreExecution $execution): void |
49
|
|
|
{ |
50
|
|
|
$activity = $execution->getActivity(); |
51
|
|
|
|
52
|
|
|
if ( |
53
|
|
|
$execution->isScope() |
54
|
|
|
&& ($this->executesNonScopeActivity($execution) || $this->isAsyncBeforeActivity($execution)) |
55
|
|
|
&& !CompensationBehavior::executesNonScopeCompensationHandler($execution) |
56
|
|
|
) { |
57
|
|
|
$execution->removeAllTasks(); |
58
|
|
|
// case this is a scope execution and the activity is not a scope |
59
|
|
|
$execution->leaveActivityInstance(); |
60
|
|
|
$execution->setActivity(getFlowScopeActivity($activity)); |
|
|
|
|
61
|
|
|
$execution->performOperation(self::deleteCascadeFireActivityEnd()); |
62
|
|
|
} else { |
63
|
|
|
if ($execution->isScope()) { |
64
|
|
|
if ($execution instanceof ExecutionEntity && !$execution->isProcessInstanceExecution() && $execution->isCanceled()) { |
65
|
|
|
// execution was canceled and output mapping for activity is marked as skippable |
66
|
|
|
$execution->setSkipIoMappings($execution->isSkipIoMappings() || $execution->getProcessEngine()->getProcessEngineConfiguration()->isSkipOutputMappingOnCanceledActivities()); |
67
|
|
|
} |
68
|
|
|
$execution->destroy(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// remove this execution and its concurrent parent (if exists) |
72
|
|
|
$execution->remove(); |
73
|
|
|
|
74
|
|
|
$continueRemoval = !$execution->isDeleteRoot(); |
75
|
|
|
|
76
|
|
|
if ($continueRemoval) { |
77
|
|
|
$propagatingExecution = $execution->getParent(); |
78
|
|
|
if ($propagatingExecution !== null && !$propagatingExecution->isScope() && !$propagatingExecution->hasChildren()) { |
79
|
|
|
$propagatingExecution->remove(); |
80
|
|
|
$continueRemoval = !$propagatingExecution->isDeleteRoot(); |
81
|
|
|
$propagatingExecution = $propagatingExecution->getParent(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($continueRemoval) { |
85
|
|
|
if ($propagatingExecution !== null) { |
86
|
|
|
// continue deletion with the next scope execution |
87
|
|
|
// set activity on parent in case the parent is an inactive scope execution and activity has been set to 'null'. |
88
|
|
|
if ($propagatingExecution->getActivity() === null && $activity !== null && $activity->getFlowScope() !== null) { |
89
|
|
|
$propagatingExecution->setActivity($this->getFlowScopeActivity($activity)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function executesNonScopeActivity(PvmExecutionImpl $execution): bool |
98
|
|
|
{ |
99
|
|
|
$activity = $execution->getActivity(); |
100
|
|
|
return $activity !== null && !$activity->isScope(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
protected function isAsyncBeforeActivity(PvmExecutionImpl $execution): bool |
104
|
|
|
{ |
105
|
|
|
return !empty($execution->getActivityId()) && empty($execution->getActivityInstanceId()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
protected function getFlowScopeActivity(PvmActivityInterface $activity): ActivityImpl |
109
|
|
|
{ |
110
|
|
|
$flowScope = $activity->getFlowScope(); |
111
|
|
|
$flowScopeActivity = null; |
112
|
|
|
if ($flowScope->getProcessDefinition() != $flowScope) { |
113
|
|
|
$flowScopeActivity = $flowScope; |
114
|
|
|
} |
115
|
|
|
return $flowScopeActivity; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getCanonicalName(): string |
119
|
|
|
{ |
120
|
|
|
return "delete-cascade-fire-activity-end"; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|