@@ -19,28 +19,23 @@ class TestScript implements ShouldQueue
1919 Queueable,
2020 SerializesModels;
2121
22+ protected $ script ;
2223 protected $ code ;
23- protected $ language ;
24- protected $ timeout ;
25- protected $ user ;
2624 protected $ data ;
2725 protected $ configuration ;
2826
2927 /**
3028 * Create a new job instance to execute a script.
3129 *
30+ * @param ProcessMaker\Models\Script $script
3231 * @param string $code
33- * @param string $language
34- * @param string $timeout
3532 * @param array $data
3633 * @param array $configuration
3734 */
38- public function __construct ($ code , $ language , $ timeout , User $ user , array $ data , array $ configuration )
35+ public function __construct ($ script , $ code , array $ data , array $ configuration )
3936 {
37+ $ this ->script = $ script ;
4038 $ this ->code = $ code ;
41- $ this ->language = $ language ;
42- $ this ->timeout = $ timeout ;
43- $ this ->user = $ user ;
4439 $ this ->data = $ data ;
4540 $ this ->configuration = $ configuration ;
4641 }
@@ -53,12 +48,9 @@ public function __construct($code, $language, $timeout, User $user, array $data,
5348 public function handle ()
5449 {
5550 try {
56- $ script = new Script ([
57- 'code ' => $ this ->code ,
58- 'language ' => $ this ->language ,
59- 'timeout ' => $ this ->timeout ,
60- ]);
61- $ response = $ script ->runScript ($ this ->data , $ this ->configuration );
51+ # Just set the code but do not save the object (preview only)
52+ $ this ->script ->code = $ this ->code ;
53+ $ response = $ this ->script ->runScript ($ this ->data , $ this ->configuration );
6254 $ this ->sendResponse (200 , $ response );
6355 } catch (Throwable $ exception ) {
6456 $ this ->sendResponse (500 , [
@@ -76,6 +68,6 @@ public function handle()
7668 */
7769 private function sendResponse ($ status , array $ response )
7870 {
79- $ this ->user ->notify (new ScriptResponseNotification ($ status , $ response ));
71+ $ this ->script -> runAsUser ->notify (new ScriptResponseNotification ($ status , $ response ));
8072 }
8173}
0 commit comments