Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · |...

35
| making happiness possible axelerant.com Drupal Camp Bangalore Getting into Drupal 8 Migration

Transcript of Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · |...

Page 2: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Mohit AgheraDrupal Developer @Axelerant

Drupal : mohit_agheraTwitter: mohit_rocks

About Me

Page 3: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

D8 Migrate in core

• The Migrate and Drupal-to-Drupal Data Migration modules have been rewritten.

• Moved into Drupal 8 core.• Their scope has been expanded.

Page 5: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

D8 Migrate in Core

• Most of the D6->D8 migration work is done - some bugs remain.

• D7->D8 migration work is in progres !!• Migration UI doesn’t comes in D8 Core {Separate

module}• Advanced feature like rollback, reset are not yet in

core.

Page 6: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrations are Plugins !!

• Yaayy… D8 Migration API is extensible using plugin.• It leverages standard D8 Plugins.• Now we are able to provide migration support to any

content and configuration data of any contrib or custom module.

Page 7: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Type of Migrations !!

• Content migration• Node migration• User migration

• Config migrations• Variable migrations • Field migrations• Entity type migrations

Page 9: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Content of migration_template file

• File “migrate.migration.migrate_example_user_role.yml”

• id : same as last part of file name

• source : configure source data; usually source plugin

• destination: destination entity• process : list of processors

plugins applied to destination field.

Page 10: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal
Page 11: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Source

• Migration configuration entity contains source key• Value is an associative array• {name} => {Configuration of plugin}

Page 12: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Process

• The Shorthands• Simple copying• Created by one plugin

process: uid:

plugin: migrationid: userssource: author

Page 13: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Process

• The full pipeline• Source value may be

passed to multiple plugins.

process:format: -

plugin: machine_name source: name

- plugin: dedupe_entity entity_type: filter_format field: format

Page 14: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Process

• Nested values• For:

• $destination['display_settings']['label']['format']• $source['display_settings']['label']['format']

• display_settings/label/format

Page 15: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin : get

• Typically, “get” plugin is start of each pipeline

• Simply copies “Source” value to “Destination”

process:bar:

plugin: get source: foo

process:bar: foo

process:foo: plugin: machine_name source: bazbar: plugin: get source: “@foo"

Page 16: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process plugin: callback

• Allows source values to be passed to a callable

• Prefered to use only one argument to avoid very complex YAML

process: destination_field:

- plugin: callback callable:

- '\Drupal\Component\Utility\Unicode' - strtolower source: source_field

Page 17: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin: Concat

• Allows to concatenate source values for relevant D8 destination values

process: new_text_field:

plugin: concatsource:

- foo - bar

process: new_text_field:

plugin: concatsource:

- foo - bar

delimiter: /

Page 18: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin: dedupe_entity

• dedupe_entity is used to prevent duplication.

• Usually used with entity types and fields.

process:format:

- plugin: machine_name source: name - plugin: dedupe_entity entity_type: filter_format field: format

Page 19: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin: dedupebase

• Avoids duplication at the destination

• We can also specify a postfix delimiter, a start position, and a length

process: new_text_field:

plugin: dedupebasesource: some_text_fieldpostfix: _start: 2length: 6

Page 20: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin : default_value

• Provides ability to set fixed default value

• sets the pipeline to the default value if the pipeline has no value (NULL, zero or empty string)

process:uid:

- plugin: migration id: users source: author - plugin: default_value default_value: 44

Page 21: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin : extract

• Pulls data from potentially multi-level arrays in the source

• Ex: Used for Drupal 7 fields

process: new_text_field:

plugin: extractsource: some_text_fieldindex: - und - 0 - value

Page 22: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process plugin : flatten

• Takes multi-dimensional arrays and flattens it.• Source : array(array(1, 2, array(3, 4)), array(5), 6) • Destination: array(1, 2, 3, 4, 5, 6).

Page 23: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin: Machine name

• Prepares source string like machine name

process:bar:

plugin: machine_name source: foo

Source: áéíK!Destination: aeik_

Page 24: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process plugin: Migration

• Maintains relationship among source and destination content in map tables.

process: uid:

plugin: migrationmigration: userssource:

- author

Page 25: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process plugin : skip_process_on_empty

• Checks whether current pipeline is empty.

• If so, skip processing. assign value to destination.

process: parent:

- plugin: skip_process_on_empty source: parent

- plugin: migration migration: d6_taxonomy_term

Page 26: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process plugin: skip_row_if_not_set

• Checks if value isset.• If set, returns value otherwise

“MigrateSkipRowException” exception

process: settings:

plugin: skip_row_if_not_setindex: contactsource: data

Page 27: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin : skip_row_on_empty

• Entire row is skipped if value is empty

process: field_type_exists:

- plugin: migration migration: d6_field source: - field_name

- plugin: extract index: - 1

- plugin: skip_row_on_empty

Page 28: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Process Plugin : Static Map

• Allows looking up a value based on a map specified in the configuration.

process:bar:

plugin: static_map source: foo

map: from: to this: that

Page 29: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

axelerant.com| making happiness possible

Static map real example

process:id:

plugin: static_map source: - module - delta map: filter: 0: filter_html_escape 1: filter_autop 2: filter_url 3: filter_htmlcorrector 4: filter_html_escape php: 0: php_code

Page 30: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal
Page 31: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Destination

• Destination has mandatory plugin key like entity:entity_type

• URL aliases are also exportable

destination: plugin: config config_name: book.settings

Page 32: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate destination

• Migrate destination: component_entity_display• Migrate destination: component_entity_form_display• Migrate destination: entity:user

Page 33: Drupal Camp Bangaloredrupalcampbangalore.org/sites/default/files/slides/Drupal 8 Migration... · | making happiness possible axelerant.com D8 Migrate in core • The Migrate and Drupal-to-Drupal

| making happiness possible axelerant.com

Migrate Example

• We will migrate users and roles from non-drupal database to drupal 8