-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathScriptResponseNotification.php
More file actions
122 lines (105 loc) · 2.52 KB
/
Copy pathScriptResponseNotification.php
File metadata and controls
122 lines (105 loc) · 2.52 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace ProcessMaker\Notifications;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Models\Script;
/**
* @deprecated version 4.1.21
*/
class ScriptResponseNotification extends Notification
{
use Queueable;
protected $status;
protected $response;
protected $watcher;
protected $nonce;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($status, array $response, $watcher = null, $nonce = null)
{
$this->status = $status;
$this->response = $response;
$this->watcher = $watcher;
$this->nonce = $nonce;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['broadcast'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
$date = new Carbon();
$response = $this->cacheResponse($this->response);
return [
'type' => 'SCRIPT_RESPONSE',
'name' => __('Script executed'),
'dateTime' => $date->toIso8601String(),
'status' => $this->status,
'watcher' => $this->watcher,
'response' => $response,
'nonce' => $this->nonce,
];
}
/**
* To broadcast.
*
* @param mixed $notifiable
*
* @return \Illuminate\Notifications\Messages\BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage($this->toArray($notifiable));
}
/**
* Get the value of status
*/
public function getStatus()
{
return $this->status;
}
/**
* Get the value of response
*/
public function getResponse()
{
return $this->response;
}
/**
* Get the value of nonce
*/
public function getNonce()
{
return $this->nonce;
}
/**
* Cache the script response to be loaded by API
*
* @return string
*/
public function cacheResponse()
{
$key = uniqid('srn', true);
Cache::put("srn.$key", $this->response, now()->addMinutes(1));
return ['key' => $key];
}
}