Skip to content

Commit f3aa0b9

Browse files
committed
debugging users migration
1 parent 887fd9d commit f3aa0b9

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/administrator/components/com_ccm/src/Helper/MigrationHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static function isSupportedFileType($sourceUrl) {
165165
* Map entity IDs using the migration map
166166
*
167167
* @param mixed $value The ID value to map
168+
* @param mixed $migrationMap The migration map
168169
* @return mixed The mapped ID or original value if no mapping found
169170
*/
170171
public static function mapEntityId($value, $migrationMap) {
@@ -175,7 +176,7 @@ public static function mapEntityId($value, $migrationMap) {
175176
foreach ($migrationMap as $entityType => $mappings) {
176177
// Check for ID mapping
177178
if (isset($mappings['ids']) && isset($mappings['ids'][$value])) {
178-
error_log("[MigrationModel] 🔗 Mapping ID '$value' using entity type '$entityType' → '{$mappings['ids'][$value]}'");
179+
error_log("[MigrationHelper] 🔗 Mapping ID '$value' using entity type '$entityType' → '{$mappings['ids'][$value]}'");
179180
return $mappings['ids'][$value];
180181
}
181182
}

src/administrator/components/com_ccm/src/Model/MigrationModel.php

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use \Joomla\CMS\Http\Http;
77
use Joomla\CMS\Factory;
88
use Joomla\CMS\Filter\OutputFilter;
9+
use Joomla\CMS\User\UserHelper;
910
use 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;

src/administrator/components/com_ccm/src/Schema/joomla-ccm.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
"ccm": "created",
3636
"format_date": "Y-m-d H:i:s"
3737
},
38-
"created_by": null,
38+
"created_by": {
39+
"ccm": "author",
40+
"type": "string",
41+
"format": "id_map"
42+
},
3943
"created_by_alias": null,
4044
"modified": {
4145
"ccm": "modified",
@@ -211,6 +215,7 @@
211215
"title": "title",
212216
"alias": "alias",
213217
"description": "description",
218+
"created_user_id": null,
214219
"language": {
215220
"default": "*"
216221
},

0 commit comments

Comments
 (0)