forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageEventDefinition.php
More file actions
53 lines (48 loc) · 1.88 KB
/
MessageEventDefinition.php
File metadata and controls
53 lines (48 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace ProcessMaker\Models;
use ProcessMaker\Models\ProcessCollaboration;
use ProcessMaker\Nayra\Bpmn\Models\MessageEventDefinition as Base;
use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
/**
* Implementation of the message element.
*/
class MessageEventDefinition extends Base
{
/**
* Implement the event definition behavior when an event is triggered.
*
* @param EventDefinitionInterface $event
* @param FlowNodeInterface $target
* @param ExecutionInstanceInterface|null $targetRequest
* @param TokenInterface|null $token
*
* @return $this
*/
public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $targetRequest = null, TokenInterface $token = null)
{
// Set collaboration
$parent = $token ? $token->getInstance() : null;
$child = $targetRequest;
if ($parent && $child) {
$collaboration_id = $parent->process_collaboration_id ?: $child->process_collaboration_id;
if (!$collaboration_id) {
$collaboration = new ProcessCollaboration();
$collaboration->process_id = $parent->process->getKey();
$collaboration->saveOrFail();
$collaboration_id = $collaboration->getKey();
}
if (!$parent->process_collaboration_id) {
$parent->process_collaboration_id = $collaboration_id;
$parent->saveOrFail();
}
if (!$child->process_collaboration_id) {
$child->process_collaboration_id = $collaboration_id;
$child->saveOrFail();
}
}
return $this;
}
}