I've been testing out the is_new flag for user migrations from D6 to D7 using the migrate_ui mapping system. Based on https://drupal.org/node/1349632#is_new, I expected the sourceid = destinationid when is_new = TRUE. However, after import, the sourceid <> destinationid. This is because, when is_new = TRUE, uid must be mapped to the relevant source field in order for it to take effect.

 $this->addFieldMapping('uid', 'uid')
         ->description(t('Preserve old user ID as uid in Drupal'));
 $this->addFieldMapping('is_new')
         ->defaultValue(TRUE);

However, it is not currently possible to map uid/nid using migrate_ui as they are destination key columns.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrP’s picture

Title: Working with is_new for users in migrate_ui » is_new -- can't map destination uid/nid for users/nodes in migrate_ui
Category: support » bug

It would appear uid and nid should be available as destination fields when editing mappings (for example, at admin/content/migrate/groups/beer/BeerUser/edit) if is_new <> DNM.

When commenting out is_new in migrate_example/beer.inc

class BeerUserMigration extends BasicExampleMigration {
...
    $this->addUnmigratedDestinations(array(
    ...
    // 'is_new',
    ...

and manually adding mappings in migrate_example/beer.inc

class BeerUserMigration extends BasicExampleMigration {
...
    // Migrate and KEEP the UID mappings.
    $this->addFieldMapping('is_new')->defaultValue(TRUE);
    $this->addFieldMapping('uid', 'aid');
    ...

Once doing so, the user id mappings are correct at admin/content/migrate/groups/beer/BeerUser and the default value for is_new = 1.

mrP’s picture

Title: is_new -- can't map destination uid/nid for users/nodes in migrate_ui » is_new: can't map destination uid/nid for users/nodes in migrate_ui
Version: 7.x-2.6-rc1 » 7.x-2.x-dev

same issue with latest dev

mrP’s picture

Priority: Normal » Major

I believe major is the appropriate priority level

mrP’s picture

The patch adds a check to allow mapping the $dest_key when is_new = TRUE. Not the most elegant patch in the world, but it seems gets the job done.

mrP’s picture

Issue summary: View changes

Updated issue summary.

mrP’s picture

Status: Active » Needs review
FileSize
700 bytes

added a check for migrations that don't support the is_new mapping

mrP’s picture

fixing a typo. third time's a charm they say...

mrP’s picture

Issue summary: View changes
mikeryan’s picture

Priority: Major » Normal
Status: Needs review » Needs work
  1. +++ b/migrate_ui/migrate_ui.pages.inc
    @@ -1056,9 +1056,12 @@ function migrate_ui_edit_mappings($form, $form_state, $group_name,
    +    if(isset($field_mappings[is_new])) {
    

    Coding standards: space after if.

  2. +++ b/migrate_ui/migrate_ui.pages.inc
    @@ -1056,9 +1056,12 @@ function migrate_ui_edit_mappings($form, $form_state, $group_name,
    +      if (isset($dest_key[$name]) && $default_is_new <> 1) {
    

    $default_is_new is tested, but may not have been set. Simplest would be to default it to 0 above.

mrP’s picture

Status: Needs work » Needs review
FileSize
741 bytes

Thanks reviewing the patch mike.

Attached is a re-roll with your suggested changes. Feel free to tweak further as you see fit.

Steve Hanson’s picture

I profess to still be a little confused by this. As far as I can tell, even with this patch applied it is still impossible to map NID to NID ? Or am I missing something?

I have set is_new to default to TRUE - but still do not get a way to map NID as a destination in the UI.

OOOOHHHH -- never mind, I see -- literally is_new has to be 1 -- not TRUE.

mrP’s picture

+++ b/migrate_ui/migrate_ui.pages.inc
@@ -1056,9 +1056,14 @@ function migrate_ui_edit_mappings($form, $form_state, $group_name,
+      // Don't map the destination key unless is_new = TRUE

add a note that TRUE = 1 in migrate_ui

aitala’s picture

I'm finding this very confusing at a UI level - what is supposed to be set to get the destination UIDs equal to the source UIDs?

Also, what happens on rollback to the sequences table? I've done this several times and it keep incrementing. I would assume on rollback it would be reset...

Eric

Mixologic’s picture

Glad I found this issue. The UI is wildly unclear.

Mixologic’s picture

+++ b/migrate_ui/migrate_ui.pages.inc
@@ -1056,9 +1056,14 @@ function migrate_ui_edit_mappings($form, $form_state, $group_name,
+    if (isset($field_mappings[is_new])) {
+      $default_is_new = $field_mappings[is_new]->getDefaultValue();

is_new should be in quotes. Otherwise its interpreted as a constant.

13rac1’s picture

Status: Needs review » Needs work

Based on above comments, this needs work.

mrP’s picture

FileSize
753 bytes

Thanks all for comments. I'm glad to see this issue maintaining some momentum.

Re-rolled patch with suggestions attached.

mrP’s picture

Status: Needs work » Needs review

  • Commit 88b538d on 7.x-2.x authored by mrP, committed by mikeryan:
    Issue #2105037 by mrP: Expose nid/uid destinations when is_new is on
    
mikeryan’s picture

Status: Needs review » Fixed
Issue tags: +Migrate 2.6

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.