Skip to content

Commit 781bbc9

Browse files
committed
Merge branch 'FOUR-12410' of github.com:ProcessMaker/processmaker into FOUR-12410
2 parents 6d56861 + db719fb commit 781bbc9

Some content is hidden

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

47 files changed

+1385
-1107
lines changed

ProcessMaker/Bpmn/Process.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function setProperty($name, $value)
4242
$properties = Cache::store('global_variables')->get($key, []);
4343
$properties[$name] = $value;
4444
try {
45+
Cache::store('global_variables')->forget($key);
4546
Cache::store('global_variables')->forever($key, $properties);
4647
} catch (\Throwable $e) {
4748
\Log::error($e->getMessage());

ProcessMaker/Events/ImportLog.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace ProcessMaker\Events;
4+
5+
use Illuminate\Broadcasting\InteractsWithSockets;
6+
use Illuminate\Broadcasting\PrivateChannel;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class ImportLog implements ShouldBroadcastNow
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
15+
public function __construct(
16+
public $userId,
17+
public $type,
18+
public $message,
19+
public $additionalParams = []
20+
) {
21+
}
22+
23+
public function broadcastAs()
24+
{
25+
return 'ImportLog';
26+
}
27+
28+
public function broadcastOn(): array
29+
{
30+
return [
31+
new PrivateChannel('ProcessMaker.Models.User.' . $this->userId),
32+
];
33+
}
34+
}

ProcessMaker/Exception/PackageNotInstalledException.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

ProcessMaker/Http/Controllers/Api/ImportController.php

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use Illuminate\Http\JsonResponse;
66
use Illuminate\Http\Request;
7-
use Illuminate\Support\Facades\Session;
7+
use Illuminate\Support\Facades\Storage;
88
use ProcessMaker\Events\TemplateCreated;
99
use ProcessMaker\Exception\ImportPasswordException;
1010
use ProcessMaker\Http\Controllers\Controller;
11-
use ProcessMaker\ImportExport\ExportEncrypted;
1211
use ProcessMaker\ImportExport\Importer;
1312
use ProcessMaker\ImportExport\Options;
13+
use ProcessMaker\Jobs\ImportV2;
1414

1515
class ImportController extends Controller
1616
{
@@ -19,6 +19,19 @@ class ImportController extends Controller
1919
*/
2020
public function preview(Request $request, $version = null): JsonResponse
2121
{
22+
if ($request->has('queue')) {
23+
Storage::putFileAs('import', $request->file('file'), 'payload.json');
24+
$hash = md5_file(Storage::path(ImportV2::FILE_PATH));
25+
$password = $request->input('password');
26+
27+
ImportV2::dispatch($request->user()->id, $password, $hash, true);
28+
29+
return response()->json([
30+
'queued' => true,
31+
'hash' => $hash,
32+
], 200);
33+
}
34+
2235
$payload = json_decode($request->file('file')->get(), true);
2336

2437
try {
@@ -39,8 +52,24 @@ public function preview(Request $request, $version = null): JsonResponse
3952
], 200);
4053
}
4154

55+
public function getImportManifest(Request $request)
56+
{
57+
$content = Storage::get(ImportV2::MANIFEST_PATH);
58+
59+
return response($content, 200)->header('Content-Type', 'application/json');
60+
}
61+
4262
public function import(Request $request): JsonResponse
4363
{
64+
if ($request->has('queue')) {
65+
Storage::put(ImportV2::OPTIONS_PATH, json_encode($request->get('options')));
66+
$password = $request->get('password');
67+
$hash = $request->get('hash');
68+
ImportV2::dispatch($request->user()->id, $password, $hash, false);
69+
70+
return response()->json(['queued' => true], 200);
71+
}
72+
4473
$jsonData = $request->file('file')->get();
4574
$payload = json_decode($jsonData, true);
4675

@@ -56,12 +85,7 @@ public function import(Request $request): JsonResponse
5685

5786
$newProcessId = $manifest[$payload['root']]->log['newId'];
5887

59-
$message = null;
60-
if (Session::get('_alert')) {
61-
$message = Session::get('_alert');
62-
}
63-
64-
return response()->json(['processId' => $newProcessId, 'message' => $message], 200);
88+
return response()->json(['processId' => $newProcessId, 'message' => Importer::getMessages()], 200);
6589
}
6690

6791
public function importTemplate(String $type, Request $request): JsonResponse
@@ -81,19 +105,6 @@ public function importTemplate(String $type, Request $request): JsonResponse
81105

82106
private function handlePasswordDecrypt(Request $request, array $payload)
83107
{
84-
if (isset($payload['encrypted']) && $payload['encrypted']) {
85-
$password = $request->input('password');
86-
if (!$password) {
87-
throw new ImportPasswordException('password required');
88-
}
89-
90-
$payload = (new ExportEncrypted($password))->decrypt($payload);
91-
92-
if ($payload['export'] === null) {
93-
throw new ImportPasswordException('incorrect password');
94-
}
95-
}
96-
97-
return $payload;
108+
return Importer::handlePasswordDecrypt($payload, $request->input('password'));
98109
}
99110
}

ProcessMaker/Http/Controllers/ProcessController.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace ProcessMaker\Http\Controllers;
44

5-
use Cache;
65
use Illuminate\Auth\Access\AuthorizationException;
76
use Illuminate\Http\Request;
87
use Illuminate\Support\Facades\Auth;
8+
use Illuminate\Support\Facades\Cache;
9+
use Illuminate\Support\Facades\Session;
10+
use Illuminate\Support\Facades\Storage;
911
use ProcessMaker\Http\Controllers\Api\ProcessController as ApiProcessController;
12+
use ProcessMaker\Jobs\ImportV2;
1013
use ProcessMaker\Models\Group;
1114
use ProcessMaker\Models\Process;
1215
use ProcessMaker\Models\ProcessCategory;
@@ -200,9 +203,37 @@ public function export(Process $process)
200203
return view('processes.export', compact('process'));
201204
}
202205

203-
public function import(Process $process)
206+
public function import(Request $request, Process $process)
204207
{
205-
return view('processes.import');
208+
if ($request->get('forceUnlock')) {
209+
$result = Cache::lock(ImportV2::CACHE_LOCK_KEY)->forceRelease();
210+
Session::flash('_alert', json_encode(['success', 'unlocked ' . $result]));
211+
212+
return redirect()->route('processes.import');
213+
}
214+
$importIsRunning = ImportV2::isRunning();
215+
216+
return view('processes.import', compact('importIsRunning'));
217+
}
218+
219+
public function downloadImportDebug(Request $request)
220+
{
221+
$hash = $request->get('hash');
222+
if ($hash !== md5_file(Storage::path(ImportV2::FILE_PATH))) {
223+
throw new \Exception('File hash does not match');
224+
}
225+
226+
$zip = new \ZipArchive();
227+
$debugFilePath = Storage::path(ImportV2::DEBUG_ZIP_PATH);
228+
if (true === ($zip->open($debugFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE))) {
229+
$zip->addFile(Storage::path(ImportV2::FILE_PATH), 'payload.json');
230+
$zip->addFile(Storage::path(ImportV2::MANIFEST_PATH), 'manifest.json');
231+
$zip->addFile(Storage::path(ImportV2::OPTIONS_PATH), 'options.json');
232+
$zip->addFile(Storage::path(ImportV2::LOG_PATH), 'log.txt');
233+
$zip->close();
234+
}
235+
236+
return response()->download($debugFilePath);
206237
}
207238

208239
/**
@@ -250,7 +281,7 @@ public function triggerStartEventApi(Process $process, Request $request)
250281
$apiRequest = new ApiProcessController();
251282
$response = $apiRequest->triggerStartEvent($process, $request);
252283

253-
return redirect('/requests/' . $response->id)->cookie('fromTriggerStartEvent', true, 1);
284+
return redirect('/requests/' . $response->id . '?fromTriggerStartEvent=');
254285
}
255286

256287
private function checkAuth()

ProcessMaker/Http/Controllers/RequestController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,22 @@ public function show(ProcessRequest $request, Media $mediaItems)
7676
$definition = $startEvent->getDefinition();
7777
$allowInterstitial = false;
7878
if (isset($definition['allowInterstitial'])) {
79-
$allowInterstitial = filter_var($definition['allowInterstitial'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
79+
$allowInterstitial = filter_var(
80+
$definition['allowInterstitial'],
81+
FILTER_VALIDATE_BOOLEAN,
82+
FILTER_NULL_ON_FAILURE
83+
);
8084
}
81-
if ($allowInterstitial && $request->user_id == Auth::id() && request()->cookie('fromTriggerStartEvent')) {
85+
if ($allowInterstitial && $request->user_id == Auth::id() && request()->has('fromTriggerStartEvent')) {
8286
$active = $request->tokens()
8387
->where('user_id', Auth::id())
8488
->where('element_type', 'task')
8589
->where('status', 'ACTIVE')
8690
->orderBy('id')->first();
8791

88-
return redirect(route('tasks.edit', ['task' => $active ? $active->getKey() : $startEvent->getKey()]))->withoutCookie('fromTriggerStartEvent');
92+
return redirect(route('tasks.edit', [
93+
'task' => $active ? $active->getKey() : $startEvent->getKey()
94+
]));
8995
}
9096
}
9197
}

ProcessMaker/ImportExport/Exporters/EnvironmentVariableExporter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class EnvironmentVariableExporter extends ExporterBase
1010

1111
public static $fallbackMatchColumn = 'name';
1212

13+
public $handleDuplicatesByIncrementing = ['name'];
14+
1315
public function export() : void
1416
{
1517
$this->addReference(DependentType::ENVIRONMENT_VARIABLE_VALUE, $this->model->value);

ProcessMaker/ImportExport/Exporters/ExporterBase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ProcessMaker\ImportExport\Dependent;
1212
use ProcessMaker\ImportExport\DependentType;
1313
use ProcessMaker\ImportExport\Extension;
14+
use ProcessMaker\ImportExport\Logger;
1415
use ProcessMaker\ImportExport\Manifest;
1516
use ProcessMaker\ImportExport\Options;
1617
use ProcessMaker\ImportExport\Psudomodels\Psudomodel;
@@ -58,6 +59,10 @@ abstract class ExporterBase implements ExporterInterface
5859

5960
public $incrementStringSeparator = ' ';
6061

62+
public $logger = null;
63+
64+
public $saveAssetsMode = null;
65+
6166
public static function modelFinder($uuid, $assetInfo)
6267
{
6368
$class = $assetInfo['model'];
@@ -120,6 +125,7 @@ public function __construct(
120125
) {
121126
$this->mode = $options->get('mode', $this->model->uuid);
122127
$this->saveAssetsMode = $options->get('saveAssetsMode', $this->model->uuid);
128+
$this->logger = new Logger();
123129
}
124130

125131
public function uuid() : string
@@ -199,9 +205,9 @@ public function runExport()
199205
{
200206
try {
201207
$extensions = app()->make(Extension::class);
202-
$extensions->runExtensions($this, 'preExport');
208+
$extensions->runExtensions($this, 'preExport', $this->logger);
203209
$this->export();
204-
$extensions->runExtensions($this, 'postExport');
210+
$extensions->runExtensions($this, 'postExport', $this->logger);
205211
} catch (ModelNotFoundException $e) {
206212
\Log::error($e->getMessage());
207213
}
@@ -210,9 +216,10 @@ public function runExport()
210216
public function runImport($existingAssetInDatabase = null)
211217
{
212218
$extensions = app()->make(Extension::class);
213-
$extensions->runExtensions($this, 'preImport');
219+
$extensions->runExtensions($this, 'preImport', $this->logger);
220+
$this->logger->log('Running Import ' . static::class);
214221
$this->import($existingAssetInDatabase);
215-
$extensions->runExtensions($this, 'postImport');
222+
$extensions->runExtensions($this, 'postImport', $this->logger);
216223
}
217224

218225
public function addReference($type, $attributes)

ProcessMaker/ImportExport/Exporters/ProcessExporter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class ProcessExporter extends ExporterBase
2727

2828
public ExportManager $manager;
2929

30-
public $discard = false;
31-
3230
public function export() : void
3331
{
3432
$process = $this->model;

ProcessMaker/ImportExport/Extension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function register($exporterClass, $class)
1414
$this->extensions[$exporterClass][] = $class;
1515
}
1616

17-
public function runExtensions($exporter, $method)
17+
public function runExtensions($exporter, $method, $logger)
1818
{
1919
$exporterClass = get_class($exporter);
2020

@@ -23,6 +23,7 @@ public function runExtensions($exporter, $method)
2323
}
2424

2525
foreach ($this->extensions[$exporterClass] as $class) {
26+
$logger->log("Running extension {$method} in {$class}");
2627
$extension = new $class();
2728
if (method_exists($extension, $method)) {
2829
$extension->$method()->call($exporter);

0 commit comments

Comments
 (0)