Skip to content

FOUR-21490 - Hide Lua and R Script Executors #7900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ public function availableLanguages()
{
$languages = [];
foreach (Script::scriptFormats() as $key => $config) {
if (in_array($key, Script::deprecatedLanguages)) {
continue;
}
if (!array_key_exists('system', $config) || (array_key_exists('system', $config) && !$config['system'])) {
$languages[] = [
'value' => $key,
Expand Down
19 changes: 17 additions & 2 deletions ProcessMaker/Models/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Script extends ProcessMakerModel implements ScriptInterface

const categoryClass = ScriptCategory::class;

const deprecatedLanguages = ['lua', 'r'];

protected $connection = 'processmaker';

protected $guarded = [
Expand Down Expand Up @@ -128,14 +130,27 @@ public static function rules($existing = null)
{
$unique = Rule::unique('scripts')->ignore($existing);

if ($existing) {
$allowedLanguages = static::scriptFormatValues();
$allowedExecutorIds = ScriptExecutor::all()->pluck('id')->toArray();
} else {
$allowedLanguages = array_filter(static::scriptFormatValues(), function ($language) {
return !in_array($language, Script::deprecatedLanguages);
});
$allowedExecutorIds = ScriptExecutor::active()->pluck('id')->toArray();
}

return [
'key' => 'unique:scripts,key',
'title' => ['required', 'string', $unique, 'alpha_spaces'],
'language' => [
'required_without:script_executor_id',
Rule::in(static::scriptFormatValues()),
Rule::in($allowedLanguages),
],
'script_executor_id' => [
'required_without:language',
Rule::in($allowedExecutorIds),
],
'script_executor_id' => 'required_without:language|exists:script_executors,id',
'description' => 'required',
'run_as_user_id' => 'required',
'timeout' => 'integer|min:0|max:65535',
Expand Down
19 changes: 17 additions & 2 deletions ProcessMaker/Models/ScriptExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class ScriptExecutor extends ProcessMakerModel
'title', 'description', 'language', 'config', 'is_system',
];

// Lua and R are deprecated. This scope can be removed
// when they are removed permanently.
public function scopeActive($query)
{
return $query->whereNotIn('language', Script::deprecatedLanguages);
}

public static function install($params)
{
$language = $params['language'];
Expand Down Expand Up @@ -140,11 +147,19 @@ public static function config($language)

public static function rules($existing = null)
{
if ($existing) {
$allowedLanguages = Script::scriptFormatValues();
} else {
$allowedLanguages = array_filter(Script::scriptFormatValues(), function ($language) {
return !in_array($language, Script::deprecatedLanguages);
});
}

return [
'title' => 'required',
'language' => [
'required',
Rule::in(Script::scriptFormatValues()),
Rule::in($allowedLanguages),
],
];
}
Expand All @@ -153,7 +168,7 @@ public static function list($language = null, $forEditMode = false)
{
$list = [];
$executors =
self::where('is_system', false)->orderBy('language', 'asc')
self::active()->where('is_system', false)->orderBy('language', 'asc')
->orderBy('created_at', 'asc');

if ($language) {
Expand Down
Loading