Skip to content

Commit fd6b6d3

Browse files
Parse webentry custom route on import
1 parent 839c53e commit fd6b6d3

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use ProcessMaker\Nayra\Exceptions\ElementNotFoundException;
2727
use ProcessMaker\Nayra\Storage\BpmnElement;
2828
use ProcessMaker\Rules\BPMNValidation;
29+
use ProcessMaker\Providers\WorkflowServiceProvider;
30+
use ProcessMaker\Package\WebEntry\Models\WebentryRoute;
2931
use Throwable;
3032

3133
class ProcessController extends Controller
@@ -914,7 +916,10 @@ public function importAssignments(Process $process, Request $request)
914916
foreach ($elements as $element) {
915917
$id = $element->getAttributeNode('id')->value;
916918
foreach ($xmlAssignable as $assign) {
917-
if ($assign['id'] == $id && array_key_exists('value', $assign) && array_key_exists('id', $assign['value'])) {
919+
if ($assign['type'] === 'webentryCustomRoute' && $assign['id'] == $id) {
920+
$this->checkForExistingRoute($assign['value']);
921+
$this->updateRoute($element, $assign['value']);
922+
} elseif ($assign['id'] == $id && array_key_exists('value', $assign) && array_key_exists('id', $assign['value'])) {
918923
$value = $assign['value']['id'];
919924
if (is_int($value)) {
920925
$element->setAttribute('pm:assignment', 'user_group');
@@ -1152,4 +1157,26 @@ private function validateImportedFile($content)
11521157
$validVersion = $hasVersion && method_exists(ImportProcess::class, "parseFileV{$decoded->version}");
11531158
return $isDecoded && $validType && $validVersion;
11541159
}
1160+
1161+
private function checkForExistingRoute($route)
1162+
{
1163+
if (WebentryRoute::where('first_segment', $route)->first()) {
1164+
return response('', 422);
1165+
}
1166+
}
1167+
1168+
private function updateRoute($node, $route)
1169+
{
1170+
$config = json_decode($node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config'), true);
1171+
if ($config['web_entry']['webentryRouteConfig']['firstUrlSegment'] !== $route) {
1172+
// update firstUrlSegment to new route
1173+
$config['web_entry']['webentryRouteConfig']['firstUrlSegment'] = $route;
1174+
1175+
// update entryUrl to new route
1176+
$path = parse_url($config['web_entry']['webentryRouteConfig']['entryUrl'], PHP_URL_PATH);
1177+
$newEntryUrl = str_replace($config['web_entry']['webentryRouteConfig']['firstUrlSegment'], $route, $path);
1178+
$config['web_entry']['webentryRouteConfig']['entryUrl'] = $newEntryUrl;
1179+
$node->setAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config', json_encode($config));
1180+
}
1181+
}
11551182
}

‎ProcessMaker/Jobs/ImportProcess.php‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ private function parseAssignables()
243243
$this->assignable = collect([]);
244244

245245
$this->parseAssignableStartEvent();
246+
$this->parseWebEntryCustomRoutes();
246247
$this->parseAssignableTasks();
247248
$this->parseAssignableCallActivity();
248249
$this->parseAssignableScripts();
@@ -276,6 +277,35 @@ private function parseAssignableStartEvent()
276277
}
277278
}
278279

280+
private function parseWebEntryCustomRoutes()
281+
{
282+
$tasks = $this->definitions->getElementsByTagName('startEvent');
283+
284+
foreach ($tasks as $task) {
285+
$config = json_decode($task->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config'), true);
286+
if (isset($config['web_entry']) && isset($config['web_entry']['webentryRouteConfig'])) {
287+
$webEntryRouteConfig= $config['web_entry']['webentryRouteConfig'];
288+
if ($webEntryRouteConfig['firstUrlSegment'] != '') {
289+
$error = null;
290+
$existingRoute = WebentryRoute::where('first_segment', $webEntryRouteConfig['firstUrlSegment'])->first();
291+
if ($existingRoute) {
292+
$error = __('Route Already Exists, please update this Route.');
293+
}
294+
295+
$this->assignable->push((object) [
296+
'type' => 'webentryCustomRoute',
297+
'id' => $task->getAttribute('id'),
298+
'name' => $task->getAttribute('name'),
299+
'prefix' => __('Assign'),
300+
'suffix' => __('Custom Web Entry Route to'),
301+
'error' => $error,
302+
'value' => $webEntryRouteConfig['firstUrlSegment'],
303+
]);
304+
}
305+
}
306+
}
307+
}
308+
279309
/**
280310
* Look for any assignable Call Activity and add them to the assignable list.
281311
*

0 commit comments

Comments
 (0)