0

I'm learning D8 migrations and working on roles and user migrations.

I copied the default d7_user_role.yml template from the user-migration module in core, and made simple adjustments to the id and label, added migration_group and saved it as migrate_plus.migration.d8_user_roles as follows:

uuid: 8e055d1d-f57b-4af1-90e0-bf4d99ba27c8
langcode: en
status: true
dependencies: {  }
id: d8_user_roles
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - 'Drupal 7'
  - Configuration
migration_group: D7-TO-D8
label: 'D8 User roles'
source:
  plugin: d7_user_role
process:
  id:
    -
      plugin: machine_name
      source: name
    -
      plugin: user_update_8002
  label: name
  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
  weight: weight
destination:
  plugin: 'entity:user_role'
migration_dependencies: null

The migration worked just fine, all 6 roles from my D7 site were migrated to my D8 site.

I tried the same with d7_user.yml, copied it, edited it by customising the id, label, added the migration_group, saved it as migrate_plus.migration.d8_users just as I did with the d8_user_roles.yml. The only difference is I added d8_user_roles.yml as a migration dependency for d8_users.yml, as shown below:

uuid: 2617bd64-fe61-4c7c-ad59-f1d989e3e8cb
langcode: en
status: true
dependencies: {  }
id: d8_users
class: Drupal\user\Plugin\migrate\User
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - 'Drupal 7'
  - Content
migration_group: D7-TO-D8
label: 'D8 User accounts'
source:
  plugin: d7_user
process:
  uid: uid
  name: name
  pass: pass
  mail: mail
  created: created
  access: access
  login: login
  status: status
  timezone: timezone
  langcode:
    plugin: user_langcode
    source: entity_language
    fallback_to_site_default: false
  preferred_langcode:
    plugin: user_langcode
    source: language
    fallback_to_site_default: true
  preferred_admin_langcode:
    plugin: user_langcode
    source: language
    fallback_to_site_default: true
  init: init
  roles:
    plugin: migration_lookup
    migration: d7_user_role
    source: roles
  user_picture:
    -
      plugin: default_value
      source: picture
      default_value: null
    -
      plugin: migration_lookup
      migration: d7_file
destination:
  plugin: 'entity:user'
migration_dependencies: 
  required:
    - d8_user_roles
  optional:
    - d7_field_instance
    - d7_file
    - language
    - default_language
    - user_picture_field_instance
    - user_picture_entity_display
    - user_picture_entity_form_display

Migrate-status showed 51 users ready for migration.

Both files were mostly unchanged except for the changes I mentioned.

The trouble is when I attempt to execute the d8_users migration I get the following error:

Migration d8_users did not meet the requirements. Missing migrations d8_user_roles. requirements: d8_user_roles.
[error]

I don't understand that because d8_user_roles is clearly included as a required dependency.

I also tried running the migration without dependencies by setting migration_dependencies to null but that throws back the following much uglier error:

InvalidArgumentException: Passed variable is not an array or object in /var/www/d8/core/modules/migrate/src/Plugin/migrate/process/Flatten.php:52                         [error]
Stack trace:
0 /var/www/d8/core/modules/migrate/src/Plugin/migrate/process/Flatten.php(52): ArrayIterator->__construct(NULL)
1 /var/www/d8/core/modules/migrate/src/MigrateExecutable.php(394): Drupal\migrate\Plugin\migrate\process\Flatten->transform(NULL,
Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row), 'permissions')
2 /var/www/d8/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php(221): Drupal\migrate\MigrateExecutable->processRow(Object(Drupal\migrate\Row), Array)
3 /var/www/d8/core/modules/migrate/src/MigrateExecutable.php(380): Drupal\migrate\Plugin\migrate\process\MigrationLookup->transform(Array,
Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row), 'roles')
4 /var/www/d8/core/modules/migrate/src/MigrateExecutable.php(203): Drupal\migrate\MigrateExecutable->processRow(Object(Drupal\migrate\Row))
5 /usr/local/share/drush/includes/drush.inc(721): Drupal\migrate\MigrateExecutable->import()
6 /usr/local/share/drush/includes/drush.inc(712): drush_call_user_func_array(Array, Array)
7 /var/www/d8/modules/contrib/migrate_tools/migrate_tools.drush.inc(317): drush_op(Array)
8 [internal function]: _drush_migrate_tools_execute_migration(Object(Drupal\user\Plugin\migrate\User), 'd8_users', Array)
9 /var/www/d8/modules/contrib/migrate_tools/migrate_tools.drush.inc(272): array_walk(Array, '_drush_migrate_...', Array)
10 /usr/local/share/drush/includes/command.inc(422): drush_migrate_tools_migrate_import('d8_users')
11 /usr/local/share/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
12 /usr/local/share/drush/includes/command.inc(199): drush_command('d8_users')
13 /usr/local/share/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
14 /usr/local/share/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
15 /usr/local/share/drush/drush.php(12): drush_main()
16 {main}

And ... I'm not sure how to interpret that error.

I would really appreciate some help to resolve the dependency issue and on how to interpret that final error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.