PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/migrate_plus/migrate_example/config/install/migrate_plus.migration.beer_user.yml

https://gitlab.com/guillaumev/alkarama
YAML | 105 lines | 44 code | 7 blank | 54 comment | 0 complexity | 81d6f121f84525ad3638ff1d56cb3151 MD5 | raw file
  1. # Migration configuration for user accounts. We've described most of what goes
  2. # into migration configuration in migrate_plus.migration.beer_term.yml, so won't
  3. # repeat that here.
  4. id: beer_user
  5. label: Beer Drinkers of the world
  6. migration_group: beer
  7. source:
  8. plugin: beer_user
  9. destination:
  10. plugin: entity:user
  11. process:
  12. pass: password
  13. mail: email
  14. init: email
  15. status: status
  16. roles:
  17. plugin: default_value
  18. default_value: 2
  19. # Here's a new process plugin - dedupe_entity. Our source site allowed there
  20. # to be multiple user accounts with the same username, but Drupal wants
  21. # usernames to be unique. This plugin allows us to automatically generate
  22. # unique usernames when we detect collisions.
  23. name:
  24. plugin: dedupe_entity
  25. # The name of the source field containing the username.
  26. source: username
  27. # These next two settings identify the destination-side field to check for
  28. # duplicates. They say "see if the incoming 'name' matches any existing
  29. # 'name' field in any 'user' entity".
  30. entity_type: user
  31. field: name
  32. # Finally, this specifies a string to use between the original value and the
  33. # sequence number appended to make the value unique. Thus, the first 'alice'
  34. # account gets the name 'alice' in Drupal, and the second one gets the name
  35. # 'alice_1'.
  36. postfix: _
  37. # Another new process plugin - callback. This allows us to filter an incoming
  38. # source value through an arbitrary PHP function. The function called must
  39. # have one required argument.
  40. created:
  41. plugin: callback
  42. # The 'registered' timestamp in the source data is a string of the form
  43. # 'yyyy-mm-dd hh:mm:ss', but Drupal wants a UNIX timestamp for 'created'.
  44. source: registered
  45. callable: strtotime
  46. # Our source data only has a single timestamp value, 'registered', which we
  47. # want to use for all four of Drupal's user timestamp fields. We could
  48. # duplicate the callback plugin we used for 'created' above - but we have a
  49. # shortcut. Putting an @ sign at the beginning of the source value indicates
  50. # that it is to be interpreted as a *destination* field name instead of a
  51. # *source* field name. Thus, if a value we need in more than one place
  52. # requires some processing beyond simply copying it directly, we can perform
  53. # that processing a single time and use the result in multiple places.
  54. changed: '@created'
  55. access: '@created'
  56. login: '@created'
  57. # Yet another new process plugin - static_map. We're making a transformation
  58. # in how we represent gender data - formerly it was integer values 0 for male
  59. # and 1 for female, but in our modern Drupal site we will be making this a
  60. # free-form text field, so we want to replace the obscure integers with
  61. # simple strings.
  62. field_migrate_example_gender:
  63. plugin: static_map
  64. # Specify the source field we're reading (containing 0's and 1's).
  65. source: sex
  66. # Tell it to transform 0 to 'Male', and 1 to 'Female'.
  67. map:
  68. 0: Male
  69. 1: Female
  70. # If the input is missing, leave the field empty. Without this, an empty
  71. # or invalid source value would cause the user record to be skipped
  72. # entirely.
  73. bypass: true
  74. # This looks like a simple migration process plugin, but there's magic
  75. # happening here. We import nodes after terms and users, because they have
  76. # references to terms and users, so of course the terms and users must be
  77. # migrated first - right? However, the favbeers field is a reference to the
  78. # beer nodes which haven't yet been migrated - we have a circular relationship
  79. # between users and nodes. The way the migration system resolves this
  80. # situation is by creating "stubs". In this case, because no beer nodes have
  81. # been created, each time a beer is looked up against the beer_node migration
  82. # nothing is found, and by default the migration process plugin creates an
  83. # empty stub node as a placeholder so the favbeers reference field has
  84. # something to point to. The stub is recorded in the beer_node map table, so
  85. # when that migration runs it knows that each incoming beer should overwrite
  86. # its stub instead of creating a new node.
  87. field_migrate_example_favbeers:
  88. plugin: migration
  89. source: beers
  90. migration: beer_node
  91. migration_dependencies: {}
  92. # When a module is creating a custom content type it needs to add an
  93. # enforced dependency to itself, otherwise the content type will persist
  94. # after the module is disabled. See: https://www.drupal.org/node/2629516.
  95. dependencies:
  96. enforced:
  97. module:
  98. - migrate_example