Skip to content

Commit 1882fcb

Browse files
committed
Disable saving new scripts and executors that use deprecated languages
1 parent 83092ea commit 1882fcb

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

ProcessMaker/Models/Script.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,27 @@ public static function rules($existing = null)
130130
{
131131
$unique = Rule::unique('scripts')->ignore($existing);
132132

133+
if ($existing) {
134+
$allowedLanguages = static::scriptFormatValues();
135+
$allowedExecutorIds = ScriptExecutor::all()->pluck('id')->toArray();
136+
} else {
137+
$allowedLanguages = array_filter(static::scriptFormatValues(), function ($language) {
138+
return !in_array($language, Script::deprecatedLanguages);
139+
});
140+
$allowedExecutorIds = ScriptExecutor::active()->pluck('id')->toArray();
141+
}
142+
133143
return [
134144
'key' => 'unique:scripts,key',
135145
'title' => ['required', 'string', $unique, 'alpha_spaces'],
136146
'language' => [
137147
'required_without:script_executor_id',
138-
Rule::in(static::scriptFormatValues()),
148+
Rule::in($allowedLanguages),
149+
],
150+
'script_executor_id' => [
151+
'required_without:language',
152+
Rule::in($allowedExecutorIds),
139153
],
140-
'script_executor_id' => 'required_without:language|exists:script_executors,id',
141154
'description' => 'required',
142155
'run_as_user_id' => 'required',
143156
'timeout' => 'integer|min:0|max:65535',

ProcessMaker/Models/ScriptExecutor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ public static function config($language)
147147

148148
public static function rules($existing = null)
149149
{
150+
if ($existing) {
151+
$allowedLanguages = Script::scriptFormatValues();
152+
} else {
153+
$allowedLanguages = array_filter(Script::scriptFormatValues(), function ($language) {
154+
return !in_array($language, Script::deprecatedLanguages);
155+
});
156+
}
157+
150158
return [
151159
'title' => 'required',
152160
'language' => [
153161
'required',
154-
Rule::in(Script::scriptFormatValues()),
162+
Rule::in($allowedLanguages),
155163
],
156164
];
157165
}

0 commit comments

Comments
 (0)