Index: modules/core/comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/migrate/modules/core/Attic/comment.inc,v retrieving revision 1.1.2.4 diff -u -p -r1.1.2.4 comment.inc --- modules/core/comment.inc 14 Jun 2009 19:59:15 -0000 1.1.2.4 +++ modules/core/comment.inc 18 Jul 2009 18:57:08 -0000 @@ -70,20 +70,15 @@ function comment_migrate_destination_imp } } - // nid and uid are initially populated with the source file's ID - translate to - // Drupal IDs - if ($comment['nid']) { - $comment['nid'] = _migrate_xlat_get_new_id('node', $comment['nid']); - } + /* + * Validation: should probably create a validation hook instead + */ if (!$comment['nid']) { $errors[] = migrate_message(t('No node found')); } - if ($comment['uid']) { - $comment['uid'] = _migrate_xlat_get_new_id('user', $comment['uid']); - if (!$comment['name']) { - $commentuser = user_load(array('uid' => $comment['uid'])); - $comment['name'] = $commentuser->name; - } + if (!$comment['name']) { + $commentuser = user_load(array('uid' => $comment['uid'])); + $comment['name'] = $commentuser->name; } if (!$comment['name']) { $errors[] = migrate_message(t('No user id or name found')); @@ -97,21 +92,42 @@ function comment_migrate_destination_imp } } + //TODO: we should probably check actual errors, some may be info messages. if (count($errors) == 0) { $cid = comment_save($comment); - if ($cid) { - // comment_save() always saves time() as the timestamp, override if we have a value - if ($comment['timestamp']) { - db_query("UPDATE {comments} - SET timestamp=%d - WHERE cid=%d", - $comment['timestamp'], $cid); - } - $sourcekey = $tblinfo->sourcekey; - migrate_add_mapping($tblinfo->mcsid, $row->$sourcekey, $cid); - } else { - $errors[] = migrate_message(t('Comment not saved')); + } + + //TODO: replace this with the migrate_destination_invoke_all(); + foreach (module_list() as $module_name) { + $function = $module_name .'_migrate_destination_complete_comment'; + if (function_exists($function)) { + timer_start($function); + $errors = array_merge($errors, (array)$function($cid, $tblinfo, $row)); + timer_stop($function); + } + } + + return $errors; +} + +function comment_migrate_destination_complete_comment(&$cid, $tblinfo, $row) { + if ($cid) { + // comment_save() always saves time() as the timestamp, override if we have a value + if ($comment['timestamp']) { + db_query("UPDATE {comments} + SET timestamp=%d + WHERE cid=%d", + $comment['timestamp'], $cid); } + $sourcekey = $tblinfo->sourcekey; + //@TODO: Factor out into caller + db_query("INSERT INTO {" . $tblinfo->maptable . "} + (sourceid, destid) + VALUES(%d, %d)", + $row->$sourcekey, $cid); + } else { + $errors[] = migrate_message(t('Comment not saved')); } return $errors; } +