Skip to content

Commit adc5821

Browse files
committed
Solving conflicts with winter
2 parents 06bd87b + f80e2e0 commit adc5821

72 files changed

Lines changed: 1526 additions & 441 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ProcessMaker/BuildSdk.php‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class BuildSdk
2626

2727
private $userId = null;
2828

29+
private $generatorCid = null;
30+
2931
public function __construct($jsonPath, $outputPath)
3032
{
3133
$this->jsonPath = $jsonPath;
@@ -40,11 +42,11 @@ public function run()
4042
$this->writeOptionsToTmpFile();
4143

4244
$this->startContainer();
43-
$this->cp($this->jsonPath, 'generator:/api-docs.json');
44-
$this->cp($this->tmpfile, 'generator:/config.json');
45+
$this->cp($this->jsonPath, $this->generatorCid . ':/api-docs.json');
46+
$this->cp($this->tmpfile, $this->generatorCid . ':/config.json');
4547
$this->generator('validate -i /api-docs.json');
4648
$this->generator('generate -g ' . $this->lang . ' -i /api-docs.json -c /config.json -o /sdk');
47-
$this->cp('generator:/sdk', $folder);
49+
$this->cp($this->generatorCid . ':/sdk', $folder);
4850
$this->stopContainer();
4951

5052
$this->fixErroneousCode($folder); // lua and python
@@ -75,13 +77,19 @@ private function imageWithTag()
7577

7678
private function startContainer()
7779
{
78-
$this->runCmd(Docker::command() . " run -t -d --entrypoint '/bin/sh' --name generator " . $this->imageWithTag());
80+
$this->generatorCid = trim($this->runCmd(Docker::command() . " run -t --stop-timeout 10 -d --entrypoint '/bin/sh' " . $this->imageWithTag()));
81+
82+
// stop the container after 5 minutes just in case this script fails before stopContainer() is called
83+
// Docker stop should always exit with code 0, because the container is probably already stopped
84+
exec('(sleep 300 && docker stop ' . $this->generatorCid . ' && docker rm ' . $this->generatorCid . ') > /dev/null 2>&1 &');
85+
86+
$this->log("Started container with cid: $this->generatorCid");
7987
}
8088

8189
private function stopContainer()
8290
{
83-
$this->runCmd(Docker::command() . ' kill generator 2>&1 || true');
84-
$this->runCmd(Docker::command() . ' rm generator 2>&1 || true');
91+
$this->runCmd(Docker::command() . ' kill ' . $this->generatorCid . ' 2>&1 || true');
92+
$this->runCmd(Docker::command() . ' rm ' . $this->generatorCid . ' 2>&1 || true');
8593
}
8694

8795
public function setLang($value)
@@ -99,12 +107,12 @@ public function getOptions()
99107
throw new Exception('Language must be specified using setLang()');
100108
}
101109

102-
return $this->runCmd(Docker::command() . ' run ' . $this->imageWithTag() . ' config-help -g ' . $this->lang);
110+
return $this->runCmd(Docker::command() . ' run --rm ' . $this->imageWithTag() . ' config-help -g ' . $this->lang);
103111
}
104112

105113
public function getAvailableLanguages()
106114
{
107-
$result = $this->runCmd(Docker::command() . ' run ' . $this->imageWithTag() . ' list -s');
115+
$result = $this->runCmd(Docker::command() . ' run --rm ' . $this->imageWithTag() . ' list -s');
108116

109117
return explode(',', $result);
110118
}
@@ -135,7 +143,7 @@ private function outputDir()
135143

136144
private function generator($cmd)
137145
{
138-
return $this->runCmd(Docker::command() . ' exec generator docker-entrypoint.sh ' . $cmd);
146+
return $this->runCmd(Docker::command() . ' exec ' . $this->generatorCid . ' docker-entrypoint.sh ' . $cmd);
139147
}
140148

141149
private function writeOptionsToTmpFile()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace ProcessMaker\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use ProcessMaker\Enums\ScriptExecutorType;
7+
use ProcessMaker\Models\ScriptExecutor;
8+
9+
class InitializeScriptMicroservice extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'processmaker:initialize-script-microservice';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Run after enabling script microservices';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
if (config('script-runner-microservice.enabled')) {
31+
// Start with an array of all microservice languages
32+
$requiredLanguages = array_flip(array_keys(ScriptExecutor::MICROSERVICE_LANGUAGES));
33+
34+
foreach (ScriptExecutor::orderBy('id', 'asc')->get() as $executor) {
35+
// Keep only the first occurrence of each language
36+
if (isset($requiredLanguages[$executor->language])) {
37+
$this->info('Keeping ' . $executor->language);
38+
} else {
39+
// Hide non-microservice languages as well as any duplicate languages
40+
$this->info('Hiding ' . $executor->language);
41+
$executor->is_system = true;
42+
$executor->type = ScriptExecutorType::Duplicate;
43+
$executor->save();
44+
}
45+
// Remove it from the required languages since we checked it
46+
unset($requiredLanguages[$executor->language]);
47+
}
48+
49+
// Create any that are missing
50+
foreach ($requiredLanguages as $language => $_) {
51+
$this->info('Creating ' . $language);
52+
ScriptExecutor::create([
53+
'language' => $language,
54+
'title' => ScriptExecutor::MICROSERVICE_LANGUAGES[$language],
55+
'description' => 'Script Executor For ' . $language,
56+
'config' => null,
57+
'is_system' => false,
58+
'type' => null,
59+
]);
60+
}
61+
} else {
62+
// Unhide any we hid above
63+
$this->info('Unhiding all script executors');
64+
ScriptExecutor::where('type', ScriptExecutorType::Duplicate)->update([
65+
'type' => null,
66+
'is_system' => false,
67+
]);
68+
}
69+
}
70+
}

‎ProcessMaker/Enums/ScriptExecutorType.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ enum ScriptExecutorType:string
66
{
77
case System = 'system';
88
case Custom = 'custom';
9+
case Duplicate = 'duplicate';
910
}

‎ProcessMaker/Http/Controllers/AboutController.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Foundation\PackageManifest;
7+
use Illuminate\Http\Client\RequestException;
78
use Illuminate\Support\Facades\Cache;
89
use Illuminate\Support\Facades\Http;
910
use Illuminate\Support\Facades\Log;
@@ -74,6 +75,8 @@ public function index()
7475
$microServices = [$aiMicroService];
7576
}
7677

78+
$microServices[] = $this->getScriptMicroService();
79+
7780
$nayraMicroService = $this->getNayraMicroServiceAbout();
7881
if ($nayraMicroService) {
7982
$microServices[] = $nayraMicroService;
@@ -98,6 +101,29 @@ public function index()
98101
);
99102
}
100103

104+
private function getScriptMicroService()
105+
{
106+
$info = [
107+
'name' => 'Script Microservice',
108+
'description' => 'Execute scripts in ProcessMaker',
109+
'status' => 'Disabled',
110+
];
111+
112+
if (config('script-runner-microservice.enabled')) {
113+
$baseUrl = config('script-runner-microservice.base_url');
114+
try {
115+
$response = Http::timeout(3)
116+
->get($baseUrl . '/accept-traffic')
117+
->throw();
118+
$info['status'] = $response->json()['message'] . ". Microservice is running at $baseUrl";
119+
} catch (Exception $e) {
120+
$info['status'] = "Error connecting to $baseUrl: " . $e->getMessage();
121+
}
122+
}
123+
124+
return $info;
125+
}
126+
101127
private function getAiMicroService()
102128
{
103129
if (hasPackage('package-ai')) {

‎ProcessMaker/Http/Controllers/Api/CssOverrideController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function store(Request $request)
8787
// Review the reset action
8888
$reset = false;
8989
if ($request->has('reset') && $request->input('reset')) {
90-
Setting::destroy($setting->id);
90+
$setting->delete();
9191
$reset = true;
9292
}
9393

‎ProcessMaker/Http/Controllers/CasesController.php‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,20 @@ public function show($case_number)
4646
$manager = app(ScreenBuilderManager::class);
4747
event(new ScreenBuilderStarting($manager, 'FORM'));
4848
// Load event ModelerStarting
49-
$managerModeler = app(ModelerManager::class);
50-
event(new ModelerStarting($managerModeler));
49+
$managerModeler = app(ModelerManager::class);
50+
event(new ModelerStarting($managerModeler));
51+
52+
// "Initialload.js" file causes an issue related to SVG in the modeler
53+
// The other scripts are not needed in the case detail
54+
$scriptsDisabled = ['package-slideshow','package-process-optimization','package-ab-testing','package-testing','initialLoad'];
55+
$managerModelerScripts = array_filter($managerModeler->getScripts(), function($script) use ($scriptsDisabled) {
56+
foreach ($scriptsDisabled as $enabledScript) {
57+
if (strpos($script, $enabledScript) !== false) {
58+
return false;
59+
}
60+
}
61+
return true;
62+
});
5163

5264
// Get all the request related to this case number
5365
$allRequests = ProcessRequest::where('case_number', $case_number)->get();
@@ -105,7 +117,7 @@ public function show($case_number)
105117
'canPrintScreens',
106118
'isProcessManager',
107119
'manager',
108-
'managerModeler',
120+
'managerModelerScripts',
109121
'bpmn',
110122
'inflightData',
111123
'pmBlockList'

‎ProcessMaker/Http/Controllers/RequestController.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
use Illuminate\Support\Facades\Route;
99
use ProcessMaker\Cache\CacheRemember;
1010
use ProcessMaker\Events\FilesDownloaded;
11+
use ProcessMaker\Events\ModelerStarting;
1112
use ProcessMaker\Events\ScreenBuilderStarting;
1213
use ProcessMaker\Filters\SaveSession;
1314
use ProcessMaker\Helpers\DefaultColumns;
1415
use ProcessMaker\Helpers\MobileHelper;
1516
use ProcessMaker\Http\Controllers\Api\UserConfigurationController;
1617
use ProcessMaker\Http\Controllers\Controller;
18+
use ProcessMaker\Http\Controllers\Process\ModelerController;
1719
use ProcessMaker\Managers\DataManager;
20+
use ProcessMaker\Managers\ModelerManager;
1821
use ProcessMaker\Managers\ScreenBuilderManager;
1922
use ProcessMaker\Models\Comment;
2023
use ProcessMaker\Models\Media as MediaModel;
@@ -172,6 +175,24 @@ public function show(ProcessRequest $request, Media $mediaItems)
172175
$manager = app(ScreenBuilderManager::class);
173176
event(new ScreenBuilderStarting($manager, ($request->summary_screen) ? $request->summary_screen->type : 'FORM'));
174177

178+
// Load event ModelerStarting
179+
$managerModeler = app(ModelerManager::class);
180+
event(new ModelerStarting($managerModeler));
181+
182+
$scriptsEnabled = ['package-slideshow','package-process-optimization','package-ab-testing','package-testing'];
183+
$managerModelerScripts = array_filter($managerModeler->getScripts(), function($script) use ($scriptsEnabled) {
184+
foreach ($scriptsEnabled as $enabledScript) {
185+
if (strpos($script, $enabledScript) !== false) {
186+
return false;
187+
}
188+
}
189+
return true;
190+
});
191+
192+
// Get all PM-Blocks
193+
$modelerController = new ModelerController();
194+
$pmBlockList = $modelerController->getPmBlockList();
195+
175196
$addons = $this->getPluginAddons('edit', compact(['request']));
176197
$dataActionsAddons = $this->getPluginAddons('edit.dataActions', []);
177198

@@ -225,6 +246,8 @@ public function show(ProcessRequest $request, Media $mediaItems)
225246
'userConfiguration',
226247
'bpmn',
227248
'inflightData',
249+
'managerModelerScripts',
250+
'pmBlockList',
228251
));
229252
}
230253

‎ProcessMaker/Http/Controllers/TemplateController.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ class TemplateController extends Controller
2424
*
2525
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
2626
*/
27-
public function edit(string $type, Request $request)
27+
public function editScreenTemplate(Request $request)
2828
{
29-
new $this->types[$type][1]->edit($request);
29+
$screenTemplate = new $this->types['screen'][1];
30+
31+
$response = $screenTemplate->show($request);
32+
33+
return view('processes.screen-builder.showTemplate')->with('id', $response['id']);
3034
}
3135

3236
/**

‎ProcessMaker/Http/Kernel.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Kernel extends HttpKernel
2222
Middleware\TrustProxies::class,
2323
Middleware\BrowserCache::class,
2424
ServerTimingMiddleware::class,
25+
Middleware\FileSizeCheck::class,
2526
];
2627

2728
/**
@@ -86,6 +87,7 @@ class Kernel extends HttpKernel
8687
'no-cache' => Middleware\NoCache::class,
8788
'admin' => Middleware\IsAdmin::class,
8889
'etag' => Middleware\Etag\HandleEtag::class,
90+
'file_size_check' => Middleware\FileSizeCheck::class,
8991
];
9092

9193
/**

0 commit comments

Comments
 (0)