@@ -249,6 +249,10 @@ private function convertSourceCmsToCcm($sourceCms, $sourceItems, $sourceType) {
249249 $ ccmItem [$ ccmKey ] = $ item [$ sourceKey ];
250250 }
251251 }
252+ // Preserve injected dependency parameter (e.g., menu_id)
253+ if (isset ($ item ['menu_id ' ])) {
254+ $ ccmItem ['menu_id ' ] = $ item ['menu_id ' ];
255+ }
252256 $ ccmItems [] = $ ccmItem ;
253257 }
254258
@@ -360,16 +364,18 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
360364 break ;
361365
362366 case 'name_map ' :
363- // Look through menus mapping to find the matching menutype
364- foreach ($ this ->migrationMap ['menus ' ]['ids ' ] as $ mapping ) {
367+ // Map using injected dependency (e.g., 'menu') to find correct menutype
368+ error_log ("[MigrationModel] Injected ccmItem2: " . json_encode ($ ccmItem ));
369+ $ oldMenuId = $ ccmItem ['menu_id ' ] ?? null ;
370+ $ value = null ;
371+ if ($ oldMenuId !== null && isset ($ this ->migrationMap ['menus ' ]['ids ' ][$ oldMenuId ])) {
372+ $ mapping = $ this ->migrationMap ['menus ' ]['ids ' ][$ oldMenuId ];
365373 if (is_array ($ mapping ) && isset ($ mapping [1 ])) {
366- $ value = $ mapping [1 ]; // Get the menutype value
367- error_log ("[MigrationModel] Found menutype: $ value " );
368- break ; // Use the first menutype found
374+ $ value = $ mapping [1 ];
375+ error_log ("[MigrationModel] Mapped menutype for menu_id $ oldMenuId: $ value " );
369376 }
370- }
371- if (empty ($ value )) {
372- error_log ("[MigrationModel] No menutype found in menus mapping " );
377+ } else {
378+ error_log ("[MigrationModel] No menutype mapping found for menu_id $ oldMenuId " );
373379 }
374380 break ;
375381 }
@@ -379,6 +385,12 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
379385 if (!empty ($ value ) && $ format ) {
380386 switch ($ format ) {
381387 case 'link_builder ' :
388+ // If this is a custom link menu-item, use the original URL instead of the template
389+ if (isset ($ ccmItem ['type ' ]) && $ ccmItem ['type ' ] === 'custom ' ) {
390+ $ value = $ ccmItem ['url ' ] ?? null ;
391+ error_log ("[MigrationModel] Using custom link URL: " . $ value );
392+ break ;
393+ }
382394 $ template = $ ccmMap ['template ' ] ?? '' ;
383395 $ params = $ ccmMap ['params ' ] ?? [];
384396 $ builtLink = $ template ;
0 commit comments