|
26 | 26 | use ProcessMaker\Nayra\Exceptions\ElementNotFoundException; |
27 | 27 | use ProcessMaker\Nayra\Storage\BpmnElement; |
28 | 28 | use ProcessMaker\Rules\BPMNValidation; |
| 29 | +use ProcessMaker\Providers\WorkflowServiceProvider; |
| 30 | +use ProcessMaker\Package\WebEntry\Models\WebentryRoute; |
29 | 31 | use Throwable; |
30 | 32 |
|
31 | 33 | class ProcessController extends Controller |
@@ -914,7 +916,10 @@ public function importAssignments(Process $process, Request $request) |
914 | 916 | foreach ($elements as $element) { |
915 | 917 | $id = $element->getAttributeNode('id')->value; |
916 | 918 | 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'])) { |
918 | 923 | $value = $assign['value']['id']; |
919 | 924 | if (is_int($value)) { |
920 | 925 | $element->setAttribute('pm:assignment', 'user_group'); |
@@ -1152,4 +1157,26 @@ private function validateImportedFile($content) |
1152 | 1157 | $validVersion = $hasVersion && method_exists(ImportProcess::class, "parseFileV{$decoded->version}"); |
1153 | 1158 | return $isDecoded && $validType && $validVersion; |
1154 | 1159 | } |
| 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 | + } |
1155 | 1182 | } |
0 commit comments