Repository navigation
Expand file tree
/
Copy pathScriptExecutor.php
More file actions
100 lines (83 loc) · 2.79 KB
/
Copy pathScriptExecutor.php
File metadata and controls
100 lines (83 loc) · 2.79 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
<?php
namespace ProcessMaker\Models;
use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Traits\HasVersioning;
use Illuminate\Validation\Rule;
class ScriptExecutor extends Model
{
use HasVersioning;
protected $fillable = [
'title', 'description', 'language', 'config'
];
public static function install($params)
{
$language = $params['language'];
$initialExecutor = self::initialExecutor($language);
if ($initialExecutor) {
$initialExecutor->update($params);
} else {
$initialExecutor = self::create($params);
Script::where('language', $language)->update(['script_executor_id' => $initialExecutor->id]);
ScriptVersion::where('language', $language)->update(['script_executor_id' => $initialExecutor->id]);
}
return $initialExecutor;
}
public static function initialExecutor($language)
{
return self::where('language', $language)
->orderBy('created_at', 'asc')
->firstOrFail();
}
public function versions()
{
return $this->hasMany(ScriptExecutorVersion::class);
}
public static function initDockerfile($language)
{
// remove try/catch block after lang packages updated
try {
$dockerfile = file_get_contents(self::packagePath($language) . '/Dockerfile');
} catch (\ErrorException $e) {
$dockerfile = '';
}
$initDockerfile = config('script-runners.' . $language . '.init_dockerfile');
// remove check after lang packages updated
if (!is_array($initDockerfile)) {
$initDockerfile = explode("\n", $initDockerfile);
}
$dockerfile .= "\n" . implode("\n", $initDockerfile);
return $dockerfile;
}
public static function packagePath($language)
{
$config = config('script-runners');
if (!isset($config[$language])) {
throw new \ErrorException("Language not in config: " . $language);
}
return config('script-runners.' . $language . '.package_path');
}
public static function rules($existing = null)
{
return [
'title' => 'required',
'language' => [
'required',
Rule::in(Script::scriptFormatValues())
],
];
}
public static function list($language = null)
{
$list = [];
$executors =
self::orderBy('language', 'asc')
->orderBy('created_at', 'asc');
if ($language) {
$executors->where('language', $language);
}
foreach ($executors->get() as $executor) {
$list[$executor->id] = $executor->language . " - " . $executor->title;
}
return $list;
}
}