Skip to content

Commit

Permalink
Merge branch 'FOUR-12410' of github.com:ProcessMaker/processmaker int…
Browse files Browse the repository at this point in the history
…o FOUR-12410
  • Loading branch information
mavalosn committed Dec 19, 2023
2 parents 6d56861 + db719fb commit 781bbc9
Show file tree
Hide file tree
Showing 47 changed files with 1,385 additions and 1,107 deletions.
1 change: 1 addition & 0 deletions ProcessMaker/Bpmn/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function setProperty($name, $value)
$properties = Cache::store('global_variables')->get($key, []);
$properties[$name] = $value;
try {
Cache::store('global_variables')->forget($key);
Cache::store('global_variables')->forever($key, $properties);
} catch (\Throwable $e) {
\Log::error($e->getMessage());
Expand Down
34 changes: 34 additions & 0 deletions ProcessMaker/Events/ImportLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace ProcessMaker\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ImportLog implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(
public $userId,
public $type,
public $message,
public $additionalParams = []
) {
}

public function broadcastAs()
{
return 'ImportLog';
}

public function broadcastOn(): array
{
return [
new PrivateChannel('ProcessMaker.Models.User.' . $this->userId),
];
}
}
9 changes: 0 additions & 9 deletions ProcessMaker/Exception/PackageNotInstalledException.php

This file was deleted.

55 changes: 33 additions & 22 deletions ProcessMaker/Http/Controllers/Api/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Events\TemplateCreated;
use ProcessMaker\Exception\ImportPasswordException;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\ImportExport\ExportEncrypted;
use ProcessMaker\ImportExport\Importer;
use ProcessMaker\ImportExport\Options;
use ProcessMaker\Jobs\ImportV2;

class ImportController extends Controller
{
Expand All @@ -19,6 +19,19 @@ class ImportController extends Controller
*/
public function preview(Request $request, $version = null): JsonResponse
{
if ($request->has('queue')) {
Storage::putFileAs('import', $request->file('file'), 'payload.json');
$hash = md5_file(Storage::path(ImportV2::FILE_PATH));
$password = $request->input('password');

ImportV2::dispatch($request->user()->id, $password, $hash, true);

return response()->json([
'queued' => true,
'hash' => $hash,
], 200);
}

$payload = json_decode($request->file('file')->get(), true);

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

public function getImportManifest(Request $request)
{
$content = Storage::get(ImportV2::MANIFEST_PATH);

return response($content, 200)->header('Content-Type', 'application/json');
}

public function import(Request $request): JsonResponse
{
if ($request->has('queue')) {
Storage::put(ImportV2::OPTIONS_PATH, json_encode($request->get('options')));
$password = $request->get('password');
$hash = $request->get('hash');
ImportV2::dispatch($request->user()->id, $password, $hash, false);

return response()->json(['queued' => true], 200);
}

$jsonData = $request->file('file')->get();
$payload = json_decode($jsonData, true);

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

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

$message = null;
if (Session::get('_alert')) {
$message = Session::get('_alert');
}

return response()->json(['processId' => $newProcessId, 'message' => $message], 200);
return response()->json(['processId' => $newProcessId, 'message' => Importer::getMessages()], 200);
}

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

private function handlePasswordDecrypt(Request $request, array $payload)
{
if (isset($payload['encrypted']) && $payload['encrypted']) {
$password = $request->input('password');
if (!$password) {
throw new ImportPasswordException('password required');
}

$payload = (new ExportEncrypted($password))->decrypt($payload);

if ($payload['export'] === null) {
throw new ImportPasswordException('incorrect password');
}
}

return $payload;
return Importer::handlePasswordDecrypt($payload, $request->input('password'));
}
}
39 changes: 35 additions & 4 deletions ProcessMaker/Http/Controllers/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace ProcessMaker\Http\Controllers;

use Cache;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use ProcessMaker\Http\Controllers\Api\ProcessController as ApiProcessController;
use ProcessMaker\Jobs\ImportV2;
use ProcessMaker\Models\Group;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCategory;
Expand Down Expand Up @@ -200,9 +203,37 @@ public function export(Process $process)
return view('processes.export', compact('process'));
}

public function import(Process $process)
public function import(Request $request, Process $process)
{
return view('processes.import');
if ($request->get('forceUnlock')) {
$result = Cache::lock(ImportV2::CACHE_LOCK_KEY)->forceRelease();
Session::flash('_alert', json_encode(['success', 'unlocked ' . $result]));

return redirect()->route('processes.import');
}
$importIsRunning = ImportV2::isRunning();

return view('processes.import', compact('importIsRunning'));
}

public function downloadImportDebug(Request $request)
{
$hash = $request->get('hash');
if ($hash !== md5_file(Storage::path(ImportV2::FILE_PATH))) {
throw new \Exception('File hash does not match');
}

$zip = new \ZipArchive();
$debugFilePath = Storage::path(ImportV2::DEBUG_ZIP_PATH);
if (true === ($zip->open($debugFilePath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE))) {
$zip->addFile(Storage::path(ImportV2::FILE_PATH), 'payload.json');
$zip->addFile(Storage::path(ImportV2::MANIFEST_PATH), 'manifest.json');
$zip->addFile(Storage::path(ImportV2::OPTIONS_PATH), 'options.json');
$zip->addFile(Storage::path(ImportV2::LOG_PATH), 'log.txt');
$zip->close();
}

return response()->download($debugFilePath);
}

/**
Expand Down Expand Up @@ -250,7 +281,7 @@ public function triggerStartEventApi(Process $process, Request $request)
$apiRequest = new ApiProcessController();
$response = $apiRequest->triggerStartEvent($process, $request);

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

private function checkAuth()
Expand Down
12 changes: 9 additions & 3 deletions ProcessMaker/Http/Controllers/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ public function show(ProcessRequest $request, Media $mediaItems)
$definition = $startEvent->getDefinition();
$allowInterstitial = false;
if (isset($definition['allowInterstitial'])) {
$allowInterstitial = filter_var($definition['allowInterstitial'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
$allowInterstitial = filter_var(
$definition['allowInterstitial'],
FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE
);
}
if ($allowInterstitial && $request->user_id == Auth::id() && request()->cookie('fromTriggerStartEvent')) {
if ($allowInterstitial && $request->user_id == Auth::id() && request()->has('fromTriggerStartEvent')) {
$active = $request->tokens()
->where('user_id', Auth::id())
->where('element_type', 'task')
->where('status', 'ACTIVE')
->orderBy('id')->first();

return redirect(route('tasks.edit', ['task' => $active ? $active->getKey() : $startEvent->getKey()]))->withoutCookie('fromTriggerStartEvent');
return redirect(route('tasks.edit', [
'task' => $active ? $active->getKey() : $startEvent->getKey()
]));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class EnvironmentVariableExporter extends ExporterBase

public static $fallbackMatchColumn = 'name';

public $handleDuplicatesByIncrementing = ['name'];

public function export() : void
{
$this->addReference(DependentType::ENVIRONMENT_VARIABLE_VALUE, $this->model->value);
Expand Down
15 changes: 11 additions & 4 deletions ProcessMaker/ImportExport/Exporters/ExporterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ProcessMaker\ImportExport\Dependent;
use ProcessMaker\ImportExport\DependentType;
use ProcessMaker\ImportExport\Extension;
use ProcessMaker\ImportExport\Logger;
use ProcessMaker\ImportExport\Manifest;
use ProcessMaker\ImportExport\Options;
use ProcessMaker\ImportExport\Psudomodels\Psudomodel;
Expand Down Expand Up @@ -58,6 +59,10 @@ abstract class ExporterBase implements ExporterInterface

public $incrementStringSeparator = ' ';

public $logger = null;

public $saveAssetsMode = null;

public static function modelFinder($uuid, $assetInfo)
{
$class = $assetInfo['model'];
Expand Down Expand Up @@ -120,6 +125,7 @@ public function __construct(
) {
$this->mode = $options->get('mode', $this->model->uuid);
$this->saveAssetsMode = $options->get('saveAssetsMode', $this->model->uuid);
$this->logger = new Logger();
}

public function uuid() : string
Expand Down Expand Up @@ -199,9 +205,9 @@ public function runExport()
{
try {
$extensions = app()->make(Extension::class);
$extensions->runExtensions($this, 'preExport');
$extensions->runExtensions($this, 'preExport', $this->logger);
$this->export();
$extensions->runExtensions($this, 'postExport');
$extensions->runExtensions($this, 'postExport', $this->logger);
} catch (ModelNotFoundException $e) {
\Log::error($e->getMessage());
}
Expand All @@ -210,9 +216,10 @@ public function runExport()
public function runImport($existingAssetInDatabase = null)
{
$extensions = app()->make(Extension::class);
$extensions->runExtensions($this, 'preImport');
$extensions->runExtensions($this, 'preImport', $this->logger);
$this->logger->log('Running Import ' . static::class);
$this->import($existingAssetInDatabase);
$extensions->runExtensions($this, 'postImport');
$extensions->runExtensions($this, 'postImport', $this->logger);
}

public function addReference($type, $attributes)
Expand Down
2 changes: 0 additions & 2 deletions ProcessMaker/ImportExport/Exporters/ProcessExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ProcessExporter extends ExporterBase

public ExportManager $manager;

public $discard = false;

public function export() : void
{
$process = $this->model;
Expand Down
3 changes: 2 additions & 1 deletion ProcessMaker/ImportExport/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function register($exporterClass, $class)
$this->extensions[$exporterClass][] = $class;
}

public function runExtensions($exporter, $method)
public function runExtensions($exporter, $method, $logger)
{
$exporterClass = get_class($exporter);

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

foreach ($this->extensions[$exporterClass] as $class) {
$logger->log("Running extension {$method} in {$class}");
$extension = new $class();
if (method_exists($extension, $method)) {
$extension->$method()->call($exporter);
Expand Down
Loading

0 comments on commit 781bbc9

Please sign in to comment.