Skip to content
Open
65 changes: 36 additions & 29 deletions ProcessMaker/Console/Commands/TransitionExecutors.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(): int
// Get the optional timeout
$timeout = $this->option('timeout') ?? 300;

if ((int)$timeout <= 60) {
if ((int) $timeout <= 60) {
$this->error('Timeout must be a greater or equal to 60');

return 1;
Expand All @@ -70,8 +70,7 @@ public function handle(): int
return 0;
}

$client = new Client($url);
$client->setTimeout($timeout);
$client = $this->createBroadcastClient($url, (int) $timeout);

$index = 0;
$total = $executors->count();
Expand All @@ -83,14 +82,14 @@ public function handle(): int
try {
$response = $this->scriptMicroserviceService->updateCustomExecutor($executors[$index]);
Log::debug('Response', ['response' => $response]);
$status = strtolower((string)($response['status'] ?? ''));
$status = strtolower((string) ($response['status'] ?? ''));

// Send subscription message (Pusher protocol example)
$client->send(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'channel' => "build-image-" . $executors[$index]->uuid
]
'channel' => 'build-image-' . $executors[$index]->uuid,
],
]));

$running = true;
Expand Down Expand Up @@ -118,7 +117,6 @@ public function handle(): int
if (!$error) {
$this->info("Executor {$executors[$index]->uuid} transitioned successfully." . PHP_EOL);
}

} catch (RequestException $e) {
$this->error("Request failed for executor {$executors[$index]->uuid}");
$this->line(PHP_EOL);
Expand All @@ -131,49 +129,58 @@ public function handle(): int

$client->close();
$index++;

} while ($index < $total);
}


return 0;
}

private function getExecutors($uuid): Collection
{
$query = ScriptExecutor::query()
->where("is_system", 0)
->where('is_system', 0)
->where(function ($query) {
$query
->whereNotIn("title", [
"PHP Executor",
"Node Executor",
"Python Executor",
"C# Executor",
"Java Executor"
->whereNotIn('title', [
'PHP Executor',
'Node Executor',
'Python Executor',
'C# Executor',
'Java Executor',
])
->orWhereNotIn("description", [
"Default PHP Executor",
"Default Javascript/Node Executor",
"Default Python Executor",
"Default C# Executor",
"Default Java Executor"
->orWhereNotIn('description', [
'Default PHP Executor',
'Default Javascript/Node Executor',
'Default Python Executor',
'Default C# Executor',
'Default Java Executor',
]);
})
->whereNotIn("language", ["php-nayra", "lua", "javascript-ssr", "sql"])
->whereNotNull("config")
->whereNotIn('language', ['php-nayra', 'lua', 'javascript-ssr', 'sql'])
->whereNotNull('config')
->where(function ($query) {
$query
->where("type", ScriptExecutorType::Custom)
->orWhereNull("type");
->where('type', ScriptExecutorType::Custom)
->orWhereNull('type');
});

if (is_array($uuid) && !empty($uuid)) {
$query->whereIn("uuid", $uuid);
} else if (is_string($uuid)) {
$query->where("uuid", $uuid);
$query->whereIn('uuid', $uuid);
} elseif (is_string($uuid)) {
$query->where('uuid', $uuid);
}

return $query->get();
}

/**
* Create the websocket client used to listen for build events.
*/
protected function createBroadcastClient(string $url, int $timeout): Client
{
$client = new Client($url);
$client->setTimeout($timeout);

return $client;
}
}
58 changes: 58 additions & 0 deletions ProcessMaker/Managers/LayoutAssetManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace ProcessMaker\Managers;

use Illuminate\Http\Request;
use InvalidArgumentException;

class LayoutAssetManager
{
/**
* Resolve the asset profile for the given request.
*/
public function forRequest(?Request $request = null): array
{
$request = $request ?? request();
$profileName = $this->resolveProfileName($request);
$profiles = config('layout-assets.profiles', []);
$defaultProfile = $profiles['default'] ?? null;

if ($defaultProfile === null) {
throw new InvalidArgumentException('layout-assets.profiles.default is not configured.');
}

if ($profileName === 'default' || !isset($profiles[$profileName])) {
return array_merge($defaultProfile, ['profile' => 'default']);
}

return array_merge($defaultProfile, $profiles[$profileName], ['profile' => $profileName]);
}

/**
* Determine whether a boolean asset flag is enabled for the request.
*/
public function requires(string $asset, ?Request $request = null): bool
{
$profile = $this->forRequest($request);

if (!array_key_exists($asset, $profile)) {
throw new InvalidArgumentException("Unknown layout asset flag: {$asset}");
}

return (bool) $profile[$asset];
}

/**
* Resolve profile name from route patterns in config.
*/
public function resolveProfileName(Request $request): string
{
foreach (config('layout-assets.routes', []) as $profileName => $patterns) {
if ($request->is(...$patterns)) {
return $profileName;
}
}

return 'default';
}
}
5 changes: 4 additions & 1 deletion ProcessMaker/Services/ScriptMicroserviceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function getScriptRunner(string $language, string $executorUuid, bool $cu

if (Cache::has($cacheKey)) {
Log::debug('Cache hit for script runner', ['cacheKey' => $cacheKey]);

return Cache::get($cacheKey);
}

Expand All @@ -211,7 +212,9 @@ public function getScriptRunner(string $language, string $executorUuid, bool $cu
return isset($item['language'], $item['id']) && $item['language'] === $language && $item['id'] === $executorUuid;
})->first();

if (!empty($result)) Cache::put($cacheKey, $result, now()->addHour());
if (!empty($result)) {
Cache::put($cacheKey, $result, now()->addHour());
}

return $result;
}
Expand Down
45 changes: 45 additions & 0 deletions config/layout-assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Layout asset profiles
|--------------------------------------------------------------------------
|
| Each profile defines which JavaScript bundles and optional vendors are
| loaded by layouts/layout.blade.php. Extend profiles here when adding
| new lightweight pages.
|
*/
'profiles' => [
'default' => [
'app' => 'js/app.js',
'app_layout' => 'js/app-layout.js',
'modeler_vendor' => true,
'monaco' => true,
],
'inbox' => [
'app' => 'js/app-core.js',
'app_layout' => 'js/app-layout-core.js',
'modeler_vendor' => false,
'monaco' => false,
],
],

/*
|--------------------------------------------------------------------------
| Route to profile mapping
|--------------------------------------------------------------------------
|
| Keys are profile names. Values are patterns accepted by Request::is().
| First matching profile wins; unmatched routes use "default".
|
*/
'routes' => [
'inbox' => [
'inbox',
'inbox/*',
'tasks',
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
Expand Down
10 changes: 10 additions & 0 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ function hasPackage($name)
}
}

if (!function_exists('layoutAssets')) {
/**
* Resolve layout JavaScript asset requirements for the current or given request.
*/
function layoutAssets(?Illuminate\Http\Request $request = null): array
{
return app(ProcessMaker\Managers\LayoutAssetManager::class)->forRequest($request);
}
}

if (!function_exists('pmUser')) {
/**
* Check both the web and api middleware for an existing user.
Expand Down
1 change: 1 addition & 0 deletions resources/js/app-core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./bootstrap-core");
Loading
Loading