1

I am trying to migrate D7 users into D10. I have enabled the following migrate modules:

  • migrate
  • migrate drupal
  • migrate plus
  • migrate tools

The migration yml is as follows:

id: create_user_account
migration_group: site_import
label: 'Create User accounts'
source:
  plugin: d7_user
process:
  uid:
    - plugin: skip_on_value
      equals: true
      source: uid
      method: row
      value:
        - 1
  name: name
  pass: pass
  mail: mail
  created: created
  access: access
  login: login
  status: status
  timezone: timezone
  langcode:
    - plugin: default_value
      default_value: 'en'
  preferred_langcode:
    - plugin: default_value
      default_value: 'en'
  preferred_admin_langcode:
    - plugin: default_value
      default_value: 'en'
  init: init
  field_user_picture:
    - plugin: sub_process
      source: field_photo
      process:
        target_id: fid
        alt: alt
        title: title
        width: width
        height: height
  field_area:
    - plugin: extract
      source: field_area
      default: null
      index:
        - 0
        - value
  field_name/value:
    - plugin: extract
      source: field_name
      default: null
      index:
        - 0
        - value
  field_phone_number_1/value:
    - plugin: extract
      source: field_phone_number_1
      default: null
      index:
        - 0
        - value
  field_phone_number_2/value:
    - plugin: extract
      source: field_phone_number_2
      default: null
      index:
        - 0
        - value
  field_position:
    - plugin: extract
      source: field_position
      default: null
      index:
        - 0
        - value
  roles:
    - plugin: callback
      callable: var_dump
      source: roles
    - plugin: sub_process
      process:
        target_id:
          plugin: static_map
          bypass: true
          source: roles
          map:
            "1": anonymous
            "2": authenticated
            "3": administrator
            "4": housing_member
            "7": content_editor
destination:
  plugin: 'entity:user'

Everything migrates as expected EXCEPT the roles.

roles var_dump outputs something like:

string(1) "3"    
string(1) "7"

for each user, but the users fail to import with the following error:

create_user_account:roles:sub_process: Input array should hold elements of type array, instead element was of type 'NULL'

which I though would be managed by 'bypass: true'.

My initial map used [without quotes]

1: anonymous

etc

But had the same error.

If I disable the roles element, the users will import as expected. How do I create the required static_map structure for the migration to work as expected?

2 Answers 2

1

The way I've been migrating users and user roles is to have two separate migrations - one for user roles, which looks like this:

id: user_roles
label: "Users roles"
migration_group: site_migration
migration_tags:
  - users
  - roles

source:
  plugin: d7_user_role

process:
  id:
    -
      plugin: machine_name
      source: name
    -
      plugin: user_update_8002

  permissions:
    -
      plugin: static_map
      source: permissions
      bypass: true
      map:
        'use PHP for block visibility': 'use PHP for settings'
        'administer site-wide contact form': 'administer contact forms'
        'post comments without approval': 'skip comment approval'
        'edit own blog entries': 'edit own blog content'
        'edit any blog entry': 'edit any blog content'
        'delete own blog entries': 'delete own blog content'
        'delete any blog entry': 'delete any blog content'
        'create forum topics': 'create forum content'
        'delete any forum topic': 'delete any forum content'
        'delete own forum topics': 'delete own forum content'
        'edit any forum topic': 'edit any forum content'
        'edit own forum topics': 'edit own forum content'
    -
      plugin: flatten

  label: name
  weight: weight

  skip_missing_permission_deprecation:
    -
      plugin: default_value
      default_value: true

destination:
  plugin: 'entity:user_role'

and the user migration itself which looks like this:

id: users
label: "Users"
migration_group: site_migration
migration_tags:
  - users

source:
  plugin: d7_user


process:
  uid:
    - plugin: skip_on_value
      equals: true
      source: uid
      method: row
      value:
        - 1
  name: name
  mail: mail
  pass: pass
  created: created
  access: access
  timezone: timezone
  login: login
  status: status
  init: init
  preferred_langcode: language
  preferred_admin_langcode: language
  roles:
    - plugin: migration_lookup
      migration: users_roles
      source: roles

destination:
  plugin: 'entity:user'

migration_dependencies:
  required:
    - user_roles

This came from config generated by the Migrate Drupal module and seems to work perfectly well. Have your user roles changed in the target site which means you're having to map the roles differently?

2
  • 1
    Migration lookup is a great way to do it.
    – Kevin
    Commented Jun 19, 2023 at 12:38
  • 1
    Hi @welly, thank you! The "permissions" section caused static_map & null errors as before, but once I removed that and ran both role & account migrations, the appropriate roles were added to the users. The problem I was trying to avoid was a d7 custom role 'editor' could have mapped to the built in D10 role 'content editor', but I can sort that out with VBO instead :)
    – ice70
    Commented Jun 19, 2023 at 13:05
0

One gotcha. If you're using the d7_ migrations included in core you have to include the Drupal 7 tag for some of them. e.g. d7_user.

  • Drupal 7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.