|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alive2212\LaravelMessageService\Jobs; |
|
4
|
|
|
|
|
5
|
|
|
use Alive2212\LaravelMessageService\AliveMessage; |
|
6
|
|
|
use Illuminate\Bus\Queueable; |
|
7
|
|
|
use Illuminate\Queue\SerializesModels; |
|
8
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
10
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
|
11
|
|
|
|
|
12
|
|
|
class MessageServiceBaseJob implements ShouldQueue |
|
13
|
|
|
{ |
|
14
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $processParams; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $modelParams; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* To user who receive message |
|
28
|
|
|
* |
|
29
|
|
|
* @var |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $to; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* From user who send message |
|
35
|
|
|
* |
|
36
|
|
|
* @var |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $from; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Body of message |
|
42
|
|
|
* |
|
43
|
|
|
* @var |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $body; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Visibility of message when user watch to message box |
|
49
|
|
|
* |
|
50
|
|
|
* @var |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $invisible; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Id of process that call this event |
|
56
|
|
|
* |
|
57
|
|
|
* @var |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $processId; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* This Job will be fired by a precess |
|
63
|
|
|
* @param array $processParams |
|
64
|
|
|
* @param array $modelParams |
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct(array $processParams, array $modelParams) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->processParams = $processParams; |
|
69
|
|
|
$this->modelParams = $modelParams; |
|
70
|
|
|
|
|
71
|
|
|
$this->initValues($processParams, $modelParams); |
|
72
|
|
|
|
|
73
|
|
|
$this->storeMessage(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Execute the job. |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function handle() |
|
82
|
|
|
{ |
|
83
|
|
|
// |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array $processParams |
|
88
|
|
|
* @param array $modelParam |
|
89
|
|
|
*/ |
|
90
|
|
|
public function initValues(array $processParams, array $modelParam) |
|
91
|
|
|
{ |
|
92
|
|
|
// get process id |
|
93
|
|
|
$this->processId = $processParams['id']; |
|
94
|
|
|
|
|
95
|
|
|
// filling data |
|
96
|
|
|
$this->invisible = $processParams['invisible']; |
|
97
|
|
|
|
|
98
|
|
|
$processFrom = $processParams['from']; |
|
99
|
|
|
if (isset($modelParam[$processFrom])) { |
|
100
|
|
|
$this->from = $modelParam[$processFrom]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$processTo = $processParams['to']; |
|
104
|
|
|
if (isset($modelParam[$processTo])) { |
|
105
|
|
|
$this->to = $modelParam[$processTo]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$this->initBody($processParams, $modelParam); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param array $processParams |
|
113
|
|
|
* @param $modelParam |
|
114
|
|
|
*/ |
|
115
|
|
|
public function initBody(array $processParams, $modelParam) |
|
116
|
|
|
{ |
|
117
|
|
|
$processBody = $processParams['body']; |
|
118
|
|
|
$processBodyParams = explode('{', $processBody); |
|
119
|
|
|
foreach ($processBodyParams as $processBodyParam) { |
|
120
|
|
|
$processBodyTag = explode('}', $processBodyParam); |
|
121
|
|
|
if (count($processBodyTag) > 1) { |
|
122
|
|
|
if (isset($modelParam[$processBodyTag[0]])) { |
|
123
|
|
|
// TODO it should get related parameters |
|
124
|
|
|
$this->body .= $modelParam[$processBodyTag[0]]; |
|
125
|
|
|
} |
|
126
|
|
|
array_shift($processBodyTag); |
|
127
|
|
|
} |
|
128
|
|
|
$this->body .= $processBodyTag[0]; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Store message into Alive Message table |
|
134
|
|
|
*/ |
|
135
|
|
|
public function storeMessage() |
|
136
|
|
|
{ |
|
137
|
|
|
// store message to Alive Message model |
|
138
|
|
|
$message = new AliveMessage(); |
|
139
|
|
|
$message->create([ |
|
|
|
|
|
|
140
|
|
|
'to' => $this->to == '' ? null : $this->to, |
|
141
|
|
|
'from' => $this->from, |
|
142
|
|
|
'body' => $this->body, |
|
143
|
|
|
'invisible' => $this->invisible, |
|
144
|
|
|
'process_id' => $this->processId, |
|
145
|
|
|
]); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.