Development

Quick Tips for a Drupal 7 to Drupal 8 Migration

Here are a few quick tips for a Drupal 7 to Drupal 8 migration. I will add more over time; admittedly it’s pretty lame right now!

For general Drupal 8 Migrate API tips, you may also want to check out my other post: Drupal 8 Migrate – Tips and Tricks

Source Plugins

If you’re using a source plugin like d7_user or d7_node it will help you understand what’s happening if you view the source code for the plugin. Pay close attention to the query(), prepareRow(), and fields() methods.

You will find the source plugins by browsing the core code. If, for example, you were looking for the d7_user source plugin you would browse to /core/modules/user/src/Plugin/migrate/source/d7/User.php . If you want to find the associated migration template you would browse to /core/modules/user/migrations/d7_user.yml . For d7_node you’d browse through the filesystem using the same pattern but with node instead of user.

Modifying the Source Plugin Query

I have a few posts on this already:

Modifying a Row

You can implement your own prepareRow() method to alter the source plugin’s easily. See Only Migrating Published Nodes in a D7 to D8 Migration first, which covers extending a source plugin. Instead of defining a query() method you’ll define a prepareRow() method. Call the parent’s prepareRow() after you’ve done your manipulations. Here’s a simple example:

Field by Field Method

I have found myself executing a migration repeatedly with --limit="10 items"  and --update  as I try to get each field working (some fields are more difficult than others). What seems to work well is keeping an eye on the database field tables as you do this. My process is, using a d7_user migration and field_user_fname as an example:

  1. Add the field to the migration yml file
  2. Re-install/import/whatever the configuration to introduce the change
  3. drush migrate:import mysite_users --limit="10 items" --update
  4. Refresh the user__field_user_fname table in Sequel Pro (the application I use to browse the DB)
  5. Look for field data. If no field data appears, or it doesn’t look right, I adjust the migration yml code, or the source plugin (if I’ve extended it). Then, I repeat this process until I start seeing the expected data in the table db table.

Leave a Reply

Your email address will not be published.