forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestScript.php
More file actions
76 lines (69 loc) · 2.05 KB
/
TestScript.php
File metadata and controls
76 lines (69 loc) · 2.05 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
<?php
namespace ProcessMaker\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use ProcessMaker\Models\Script;
use Throwable;
use Illuminate\Queue\SerializesModels;
use ProcessMaker\Notifications\ScriptResponseNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use ProcessMaker\Models\User;
class TestScript implements ShouldQueue
{
use Dispatchable,
InteractsWithQueue,
Queueable,
SerializesModels;
protected $script;
protected $current_user;
protected $code;
protected $data;
protected $configuration;
/**
* Create a new job instance to execute a script.
*
* @param ProcessMaker\Models\Script $script
* @param ProcessMaker\Models\User $current_user
* @param string $code
* @param array $data
* @param array $configuration
*/
public function __construct(Script $script, User $current_user, $code, array $data, array $configuration)
{
$this->script = $script;
$this->current_user = $current_user;
$this->code = $code;
$this->data = $data;
$this->configuration = $configuration;
}
/**
* Execute the script task.
*
* @return void
*/
public function handle()
{
try {
# Just set the code but do not save the object (preview only)
$this->script->code = $this->code;
$response = $this->script->runScript($this->data, $this->configuration);
$this->sendResponse(200, $response);
} catch (Throwable $exception) {
$this->sendResponse(500, [
'exception' => get_class($exception),
'message' => $exception->getMessage(),
]);
}
}
/**
* Send a response to the user interface
*
* @param int $status
* @param array $response
*/
private function sendResponse($status, array $response)
{
$this->current_user->notify(new ScriptResponseNotification($status, $response));
}
}