66use \Joomla \CMS \Http \Http ;
77use Joomla \CMS \Factory ;
88use Joomla \CMS \Filter \OutputFilter ;
9+ use Joomla \CMS \User \UserHelper ;
910use Reem \Component \CCM \Administrator \Helper \MigrationHelper ;
1011
1112/**
@@ -328,8 +329,8 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
328329 }
329330 }
330331
331- // Handle value mapping
332- if (isset ($ ccmMap ['map ' ]) && is_array ($ ccmMap ['map ' ])) {
332+ // Handle value mapping (skip for array values as they need special handling)
333+ if (isset ($ ccmMap ['map ' ]) && is_array ($ ccmMap ['map ' ]) && ! is_array ( $ value ) ) {
333334 $ value = $ ccmMap ['map ' ][$ value ] ?? ($ ccmMap ['default ' ] ?? $ value );
334335 }
335336
@@ -346,12 +347,17 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
346347
347348 if (empty ($ value ) && $ format ) {
348349 switch ($ format ) {
350+ case 'password ' :
351+ error_log ("[MigrationModel] Generating password for the user: " . $ ccmItem ['username ' ]);
352+ $ value = UserHelper::genRandomPassword (16 );
353+ error_log ("[MigrationModel] Generated password: " . $ value );
354+ break ;
355+
349356 case 'alias ' :
350357 error_log ("[MigrationModel] Formatting alias for the title: " . $ ccmItem ['title ' ]);
351358 $ value = OutputFilter::stringURLSafe ($ ccmItem ['title ' ]);
352359 break ;
353360
354-
355361 case 'name_map ' :
356362 // Look through menus mapping to find the matching menutype
357363 foreach ($ this ->migrationMap ['menus ' ]['ids ' ] as $ mapping ) {
@@ -424,15 +430,32 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
424430 break ;
425431 case 'array ' :
426432 if (is_array ($ value )) {
427- $ mappedValues = [];
428- foreach ($ value as $ arrayValue ) {
429- if (is_numeric ($ arrayValue ) || (is_string ($ arrayValue ) && ctype_digit (trim ($ arrayValue )))) {
430- $ numericValue = intval ($ arrayValue );
431- $ mappedValue = MigrationHelper::mapEntityId ($ numericValue , $ this ->migrationMap );
433+ // Check if we have a role mapping configuration
434+ error_log ("ccmMap: " . json_encode ($ ccmMap ));
435+ if (isset ($ ccmMap ['map ' ]) && is_array ($ ccmMap ['map ' ])) {
436+ // Handle role mapping directly in the model
437+ error_log ("[MigrationModel] Role mapping configuration found for array value: " . json_encode ($ value ));
438+ $ mappedValues = [];
439+ foreach ($ value as $ arrayValue ) {
440+ // Map roles using the provided mapping
441+ $ mappedValue = $ ccmMap ['map ' ][$ arrayValue ] ?? ($ ccmMap ['default ' ] ?? $ arrayValue );
442+ error_log ("[MigrationModel] Role mapping: $ arrayValue -> $ mappedValue " );
432443 $ mappedValues [] = $ mappedValue ;
433444 }
445+ $ value = $ mappedValues ;
446+ } else {
447+ // Handle numeric ID mapping (existing functionality)
448+ error_log ("[MigrationModel] Numeric ID mapping for array value: " . json_encode ($ value ));
449+ $ mappedValues = [];
450+ foreach ($ value as $ arrayValue ) {
451+ if (is_numeric ($ arrayValue ) || (is_string ($ arrayValue ) && ctype_digit (trim ($ arrayValue )))) {
452+ $ numericValue = intval ($ arrayValue );
453+ $ mappedValue = MigrationHelper::mapEntityId ($ numericValue , $ this ->migrationMap );
454+ $ mappedValues [] = $ mappedValue ;
455+ }
456+ }
457+ $ value = $ mappedValues ;
434458 }
435- $ value = $ mappedValues ;
436459 } elseif (is_numeric ($ value ) || (is_string ($ value ) && ctype_digit (trim ($ value )))) {
437460 $ mappedValue = MigrationHelper::mapEntityId (intval ($ value ), $ this ->migrationMap );
438461 $ value = [$ mappedValue ];
@@ -488,6 +511,14 @@ private function convertCcmToTargetCms($ccmItems, $targetCms, $targetType) {
488511
489512 case 'id_map ' :
490513 if (!empty ($ value ) && ($ type === 'string ' || $ type === 'integer ' )) {
514+ // Handle object with ID extraction (like author object)
515+ if (is_array ($ value ) && isset ($ value ['ID ' ])) {
516+ $ value = $ value ['ID ' ];
517+ error_log ("[MigrationModel] Extracted ID from object for id_map: " . $ value );
518+ } elseif (is_object ($ value ) && isset ($ value ->ID )) {
519+ $ value = $ value ->ID ;
520+ error_log ("[MigrationModel] Extracted ID from object for id_map: " . $ value );
521+ }
491522 $ value = MigrationHelper::mapEntityId ($ value , $ this ->migrationMap );
492523 }
493524 break ;
0 commit comments