Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
| making happiness possible axelerant.com
Drupal Camp Bangalore
Getting into Drupal 8 Migration
| making happiness possible axelerant.com
Mohit AgheraDrupal Developer @Axelerant
Drupal : mohit_agheraTwitter: mohit_rocks
About Me
| 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.
| making happiness possible axelerant.com
D8 Migrate Background
• core/modules/migrate• core/modules/migrate_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.
| 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.
| making happiness possible axelerant.com
Type of Migrations !!
• Content migration• Node migration• User migration
• Config migrations• Variable migrations • Field migrations• Entity type migrations
| making happiness possible axelerant.com
The anatomy of migration
• Migrate source• Migrate process • Migrate destination
| 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.
| making happiness possible axelerant.com
Migrate Source
• Migration configuration entity contains source key• Value is an associative array• {name} => {Configuration of plugin}
| making happiness possible axelerant.com
Migrate Process
• The Shorthands• Simple copying• Created by one plugin
process: uid:
plugin: migrationid: userssource: author
| 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
| making happiness possible axelerant.com
Migrate Process
• Nested values• For:
• $destination['display_settings']['label']['format']• $source['display_settings']['label']['format']
• display_settings/label/format
| 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"
| 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
| 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: /
| 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
| 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
| 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
| 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
| 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).
| 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_
| making happiness possible axelerant.com
Process plugin: Migration
• Maintains relationship among source and destination content in map tables.
process: uid:
plugin: migrationmigration: userssource:
- author
| 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
| 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
| 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
| 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
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
| 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
| making happiness possible axelerant.com
Migrate destination
• Migrate destination: component_entity_display• Migrate destination: component_entity_form_display• Migrate destination: entity:user
| making happiness possible axelerant.com
Migrate Example
• We will migrate users and roles from non-drupal database to drupal 8
| making happiness possible axelerant.com
Questions ??
| making happiness possible axelerant.com
Thank you !!