forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowMessageEvent.php
More file actions
63 lines (52 loc) · 1.7 KB
/
ThrowMessageEvent.php
File metadata and controls
63 lines (52 loc) · 1.7 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
54
55
56
57
58
59
60
61
62
63
<?php
namespace ProcessMaker\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface;
use ProcessMaker\Repositories\DefinitionsRepository;
class ThrowMessageEvent extends BpmnAction implements ShouldQueue
{
use Dispatchable,
InteractsWithQueue,
Queueable;
private const maxJobs = 10;
public $messageRef;
public $payload;
public $instanceId;
public $elementId;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($instanceId, $elementId, $messageRef, array $payload = [])
{
$this->messageRef = $messageRef;
$this->payload = $payload;
$this->instanceId = $instanceId;
$this->elementId = $elementId;
}
public function action(ProcessRequest $instance, CatchEventInterface $element)
{
$repository = new DefinitionsRepository;
$eventDefinition = $repository->createMessageEventDefinition();
$message = $repository->createMessage();
$message->setId($this->messageRef);
$eventDefinition->setPayload($message);
$eventDefinition->setProperty('messageRef', $this->messageRef);
$this->engine->getEventDefinitionBus()->dispatchEventDefinition(
null,
$eventDefinition,
null
);
if ($this->payload) {
foreach ($this->payload as $key => $value) {
$instance->getDataStore()->putData($key, $value);
}
}
}
}