diff --git a/upgrades/2024_02_07_113706_web_entry_url_fixer.php b/upgrades/2024_02_07_113706_web_entry_url_fixer.php new file mode 100644 index 0000000000..e74df9a3b1 --- /dev/null +++ b/upgrades/2024_02_07_113706_web_entry_url_fixer.php @@ -0,0 +1,75 @@ +updateWebEntryUrl($process, $appUrl); + } + }); + } + + /** + * Reverse the upgrade migration. + */ + public function down(): void + { + // No down migration needed. + } + + /** + * Updates the web entry URL for a given process. + */ + private function updateWebEntryUrl(Process $process, string $appUrl): void + { + $definitions = $process->getDefinitions(true); + $elements = Utils::getElementByMultipleTags($definitions, [ + 'bpmn:task', + 'bpmn:startEvent', + ]); + foreach ($elements as $element) { + $config = $element->getAttribute('pm:config') ?? '[]'; + $decodedConfig = json_decode($config, true); + $entryUrl = Arr::get($decodedConfig, 'web_entry.webentryRouteConfig.entryUrl'); + + // If the entry URL is not a valid URL, then update it. + if ($entryUrl && !filter_var($entryUrl, FILTER_VALIDATE_URL)) { + $newEntryUrl = rtrim($appUrl, '/') . '/' . ltrim($entryUrl, '/'); + Arr::set($decodedConfig, 'web_entry.webentryRouteConfig.entryUrl', $newEntryUrl); + $element->setAttribute('pm:config', json_encode($decodedConfig)); + } + } + + $process->bpmn = $definitions->saveXml(); + $process->save(); + } +}