Drupal 8 Migrations

Introduction:

Migrate is now in Drupal 8 core, but there are important contrib modules, Migrate Plus and Migrate Tools. These provide additional migration classes, and drush tools. Migrate Plus started work on a migration UI, but it is currently broken.

Migrations are pretty easy when you can just populate a config file and run it. For a limited number of items, a straightforward source, and no relationships in the content, it should be a breeze. You may get by by adding print_r statements that expose things when you run drush, or for better results, get xdebug running.

When migrations involve content relationships, modifying values, or large data sets, things get more complicated.

 

Instructions:

  1. Figure out how to get the source data. If this is a SQL query or REST api call, work it out in isolation of your migration code to avoid confusion.
  2. Determine if the migrate and migrate_plus classes will work for you, or if you will need to extend one or more of them. These are source, destination, parser, and fetcher classes. Migrate plus contains additional classes for JSON and XML.
  3. Get the migration working for a limited # of items. IE a single page of a batched api call, or items for a single user.
  4. Finish complete migration.

 

Dynamic Migrations (outdated):

https://www.drupal.org/docs/8/api/migrate-api/building-dynamic-migratio…

Add Migrate Plus to documentation (issue):

https://www.drupal.org/node/2816805

Multi-page source:

https://www.drupal.org/node/2640516

Set parameters for dynamic migration config:

https://www.jeffgeerling.com/blog/2016/migrate-custom-json-feed-drupal-…

Drupal API

https://api.drupal.org/api/drupal/core%21modules%21migrate%21migrate.ap…



This page above is missing important info about migrate hooks that can be found in migrate.api.php:

https://api.drupal.org/api/drupal/core%21modules%21migrate%21migrate.ap…

hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)

hook_migration_plugins_alter(array &$migrations)

Resources:

 

Questions:

  • How does migrate-status look up stats? Why did it take so long for my migration?
  • Should you modify your migration by implementing hooks or writing your own classes?