Migrating to Drupal 8

http://rocketeerbkw.github.io/slides/austin-drupal-users-group/migrating-to-drupal-8/

Migrate Module

The migrate module provides a flexible framework for migrating content into Drupal from other sources (e.g., when converting a web site from another CMS to Drupal).

Migrate

  • In Drupal 8 core
  • Support for D6 AND D7
  • Done on new site, not in-place
  • Modern, OO data transportation
  • Repeatable

Upgrade

  • Done on current site
  • Raw SQL queries
  • Error prone
  • Mistakes = start over

Drupal 8.1.x

  • Migrate UI in core
  • Better support for D7
  • Plugins instead of Config Entities
  • May break migrations from 8.0.x

Contrib Extensions

"Simple" Example

  • rocketeerbkw.com
  • Basic blog with Drupal 7
  • 9 contrib, 1 custom
  • Bartik theme
# Download Drupal
drush dl

# Install with minimal profile
drush si minimal --account-name=admin --account-pass=admin --db-url=mysql://root@127.0.0.1/r8

# Download contrib modules
drush dl markdown pathauto token redirect google_analytics ctools migrate_upgrade

# Need 8.x-2.x of migrate_plus
drush dl --select migrate_plus

# Enable modules you want to migrate
drush en -y color contact block_content contextual menu_link_content options path rdf shortcut taxonomy link migrate_drupal_ui image toolbar markdown pathauto token redirect google_analytics migrate_upgrade

# Run the migration
# In the UI
http://r8.dev/upgrade
# Via drush
drush migrate-upgrade --legacy-db-url=mysql://root@127.0.0.1/r7 --legacy-root=/Users/rocketeerbkw/Sites/r7
            

"Complex" example

  • truthunity.net
  • Multilingual, content hierarchy, relationships, access control, multimedia, kitchen sink
  • >100 contrib, Many custom
  • Custom theme

Is contrib ready?

Custom modules?

Custom theme?

Verdict?

7 to 8 is probably not ready. But you can help!

6 to 8 is suppossed to have better support.

Advanced Migrations

  • Merge or split content types
  • Merge or split fields
  • Transform data between sites
  • Rearchitect but keep content
  • Only migrate portion of old site
  • Long-term development
  • Long-running migrations
  • Complex migration dependencies
  • Etc.

New Business Requirement

  • All taxonomy terms must be UPPERCASE

1. Export migrations as config instead of running

drush migrate-upgrade --configure-only --legacy-db-url=mysql://root@127.0.0.1/r7 --legacy-root=/Users/rocketeerbkw/Sites/r7

2. Configure source database in settings.php

3. Migrate vocabularies

drush mi upgrade_d7_taxonomy_vocabulary

4. Export, Modify, Import terms migration

uuid: 70ba6e1b-0149-48b9-893a-ad0611935860
langcode: en
status: true
dependencies: {  }
id: upgrade_d7_taxonomy_term
migration_tags:
  - 'Drupal 7'
migration_group: migrate_drupal_7
label: 'Taxonomy terms'
source:
  plugin: taxonomy_term
process:
  tid: tid
  vid:
    plugin: migration
    migration: upgrade_d7_taxonomy_vocabulary
    source: vid
  name: name
  description: description
  weight: weight
  parent:
    plugin: migration
    migration: upgrade_d7_taxonomy_term
    source: parent
  changed: timestamp
destination:
  plugin: 'entity:taxonomy_term'
migration_dependencies:
  required:
    - upgrade_d7_taxonomy_vocabulary
  optional: {  }
uuid: 70ba6e1b-0149-48b9-893a-ad0611935860
langcode: en
status: true
dependencies: {  }
id: upgrade_d7_taxonomy_term
migration_tags:
  - 'Drupal 7'
migration_group: migrate_drupal_7
label: 'Taxonomy terms'
source:
  plugin: taxonomy_term
process:
  tid: tid
  vid:
    plugin: migration
    migration: upgrade_d7_taxonomy_vocabulary
    source: vid
  name:
    plugin: callback
    callable: strtoupper
    source: name
  description: description
  weight: weight
  parent:
    plugin: migration
    migration: upgrade_d7_taxonomy_term
    source: parent
  changed: timestamp
destination:
  plugin: 'entity:taxonomy_term'
migration_dependencies:
  required:
    - upgrade_d7_taxonomy_vocabulary
  optional: {  }

5. Rebuild cache

drush cache-rebuild

6. Migrate terms

drush mi upgrade_d7_taxonomy_term

New Business Requirement

  • New branding, update employee email addresses

1. Export migrations as config instead of running

drush migrate-upgrade --configure-only --legacy-db-url=mysql://root@127.0.0.1/r7 --legacy-root=/Users/rocketeerbkw/Sites/r7

2. Configure source database in settings.php

3. Custom module with custom source plugin

drupal generate:module
getSourceProperty('mail');
    $new_mail = str_replace('@evilcorp.com', '@rockstars.io', $old_email);
    $row->setSourceProperty('mail', $new_mail);

    return parent::prepareRow($row);
  }

}

4. Export, Modify, Import user migration

uuid: 72303b9e-6cd6-4c96-9ab2-e5c58a4697b7
langcode: en
status: true
dependencies: {  }
id: upgrade_d7_user
migration_tags:
  - 'Drupal 7'
migration_group: migrate_drupal_7
label: '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: language
  preferred_langcode: language
  preferred_admin_langcode: language
  init: init
  roles:
    plugin: migration
    migration: upgrade_d7_user_role
    source: roles
  user_picture:
    -
      plugin: default_value
      source: picture
      default_value: null
    -
      plugin: migration
      migration: d7_file
destination:
  plugin: 'entity:user'
migration_dependencies:
  required:
    - upgrade_d7_user_role
  optional:
    - upgrade_d7_file
    - upgrade_user_picture_field_instance
    - upgrade_user_picture_entity_display
    - upgrade_user_picture_entity_form_display
uuid: 72303b9e-6cd6-4c96-9ab2-e5c58a4697b7
langcode: en
status: true
dependencies: {  }
id: upgrade_d7_user
migration_tags:
  - 'Drupal 7'
migration_group: migrate_drupal_7
label: 'User accounts'
source:
  plugin: evilcorp_migrations_user
process:
  uid: uid
  name: name
  pass: pass
  mail: mail
  created: created
  access: access
  login: login
  status: status
  timezone: timezone
  langcode: language
  preferred_langcode: language
  preferred_admin_langcode: language
  init: init
  roles:
    plugin: migration
    migration: upgrade_d7_user_role
    source: roles
  user_picture:
    -
      plugin: default_value
      source: picture
      default_value: null
    -
      plugin: migration
      migration: d7_file
destination:
  plugin: 'entity:user'
migration_dependencies:
  required:
    - upgrade_d7_user_role
  optional:
    - upgrade_d7_file
    - upgrade_user_picture_field_instance
    - upgrade_user_picture_entity_display
    - upgrade_user_picture_entity_form_display

5. Rebuild cache

drush cache-rebuild

6. Migrate users

drush mi --execute-dependencies upgrade_d7_user

Non-Drupal Migrations

The migrate module was originally created to facilitate migrations from platforms other than Drupal.

All the concepts used for migrating from Drupal 7 can just as easily be used to migrate from WordPress, Joomla!, etc.

Resources

Questions

@rocketeerbkw
rocketeerbkw@gmail.com
rocketeerbkw.com