Thanks
Welcome
If you're new to Drupal, we recommend starting here: What Is Drupal?
Or if you already have some Drupal experience, click the Explore button and learn something new.
We now have a site with most of the basic functionality the Band Wagon project needs to start. However, one important piece remains: streamlining the content editing process, and allowing easy image and video integration in posts. In this lesson we will compare content editing tools and discuss how to integrate our media directly into the body of our content.
Today we finish up the Importing Data With Migrate and Drupal 7 series. In four hours of lessons we've covered everything from Migrate module concepts to writing your own custom data migration. To wrap things up this week, we are going to take a look at using other data sources, like CSV files, as well as different destinations aside from nodes.
Up to this point we've focused focused on creating nodes as the result of our migrations. The Migrate module however supports a number of different destinations that we can use when importing data. In this lesson we'll take a look at the destination classes that the Migrate module provides for us and talk about what each one is used for and where to find more information and examples of using them. Then we'll implement a migration that imports data as vocabulary terms using the MigrateDestinationTerm class.
It's almost unheard of to write a data import that just works on the first try. Our examples have all been written using data that is known to be in good shape, and to be honest we've avoided even trying to import some of the data because it ended up being problematic and we wanted to focus on working with the Migrate module and not debugging the problems in your source data. In the real world though, you're going to end up with problematic rows in your source data and you'll need to get them resolved.
In this lesson we'll run the complete player migration and end up with a couple of rows that fail to import because of an oversight in our code. We can use the migrate UI to get a sense of what is failing and why. Then we'll use a combination of options available to the drush migrate command and some strategically placed print_r's to debug and resolve the problem rows. Finally, we'll use a trick to get the Migrate module to re-import all the problem rows but not the already imported rows.
So far all the data we've been migrating has come from a MySQL database but Migrate supports a number of other data sources which we can access by using a different source migration class. In this lesson we'll look at the source migration classes that are available with the migrate module and talk about what each one could be used for. Then we'll implement a migration that imports data from a CSV file since that's another common way of receiving source data.
For your convenience, we've included a copy of the sample data in the companion files. This is a duplicate of the data from lesson Set Up Migrate Demo Site and Source Data. If you've been following the lessons in order, you should not need to download the sample data set again.
Migrate Source Class documentation
Drupal 8 has come a long way since Drupal 7 to being easier to use out of the box. When I built sites for people using Drupal 7 the biggest complaint was the lack of a WYSIWYG editor. At some point installing WYSIWYG module and adding an editor role just became part of my usual installation of modules. This process wasn't complicated, but it was rather annoying.
First you had to install the module, then download the third party WYSIWYG files from another website. Once you had all the components you needed, you then had to setup text formats to use the editing interface, and also configure the role for your content managers to assign correct permissions. My favorite part of the process was the web page of check boxes of buttons you could add to the toolbar. The page was hideous and not very configurable if you'd added any extra add-ons to your WYSIWYG.
It is that time of the week when we publish a new Drupalize.Me podcast. You're excited. We're excited. Unfortunately we don’t have one for you today. We recorded a great podcast on getting involved with Drupal 8 with Joe Shindelar, Juampy, Alex Bronstein, and Larry Garfield. It was a fun podcast talking about all the new things that excite us about Drupal 8. Somehow the final recorded audio file turned bad about 10 minutes into it. Normally we have a fall-back plan which involves two people recording the podcast.
Very few migrations are simple and straight-forward enough that a simple field mapping gets all of the little bits you need. In this week's Importing Data With Migrate and Drupal 7 lessons, we take a look at some complicated field mappings. We are going to add some new data we need to import, with team information. The team data is related to our player data through a relationship, and a player can have multiple teams they've played for.
This lesson is a short one but it covers an important topic, multi-value fields. Almost any field in Drupal can be configured to support more than one value being entered for a single field. Our teams entityreference field is a good example of this, a player could have played for one or more team over the course of their career. This lesson will look at two different ways to map multiple values for a single field.
First we'll look at doing it in a callback method where we perform an additional query and then use the values returned by that query. And second we'll look at using the field mapping's separator method to take a column in a source row that has multiple values separated by a comma and import them as individual field values.
The infamous causality dilemma of the chicken and the egg examines which of the two came first constantly battling with the fact that you need one to produce the other. It's a vicious circle. In this lesson we're going to explore this dilemma in the context of data migrations. Imagine a scenario where you've got an article node type that has a reference field for similar articles which you need to populate with the node ID of the similar articles. During a migration when the article is being imported the article that is being referenced may or may not exist already. If it doesn't exist already how do we know what ID we need to put into the reference field?
One option would be to solve this problem using multiple passes. A first pass that goes through and creates all the articles, and a second that comes back through and updates the similar articles field. Though what happens if the similar articles field is required? You wouldn't be able to save the article without a value in that field the first time around? So you see how this quickly becomes another example of the chicken or the egg problem?
Lucky for us the migrate module has a solution to this called stub migrations. A process that allows creating a stub or a shell for the referenced but not yet created article so that we can use it's unique ID, then when that article is encountered in the migration it will update the stub rather than create a new article.
In this lesson we're going to take a look at creating relationships between two Drupal nodes during a migration. In our case we've got player and team nodes, and each player node has an entity reference to a team node which we need to populate during our migration. In order for this to work we need to ensure that the team node has already been created so that we know the unique node.nid to use in the entity reference field for the player.
To accomplish this we're going to write a migration for team data and ensure that it is run prior to our player migration being run. Then we're going to make use of the mapping between source and destination rows that the Migrate module is tracking for teams so that during a player migration we can lookup the corresponding team node's nid and make use of it.
We are super excited to introduce you to our new Interactive Designer, Justin Harrell. Justin started with us right before DrupalCon Prague, and so came over to Europe with the rest of the team for an intense introduction to the Drupal world.
If you're new to Drupal, we recommend starting here: What Is Drupal?
Or if you already have some Drupal experience, click the Explore button and learn something new.
In this lesson we're going to finish mapping the fields for the player migration and learn about how to deal with source data that requires some additional massaging before being saved to the destination. We'll learn about the use of field mapping callback functions and the migration's prepareRow method as possible spots to perform additional logic during a migration. Then we'll use these techniques to combine our player first and last name fields together for the node title field, deal with our birth and death date fields by concatenating the three source columns together into a single date string, and finally add some additional information to the notes field during import that will allow us to track imported records in the future.
Note: This lesson was recorded using the 7.x-2.6 version of the date module, however the 7.x-2.7 version is now out which contains some changes to the module's integration with the migrate module. The biggest change being that the date_migrate module is no longer required and has been deprecated. You can read more about the changes here: https://drupal.org/node/2034231
Although not required when writing your own migration, the Migrate module provides ways for us to decorate our migrations with additional information making it easier to keep track of who is working on what, what needs to get done, and related issues. We've already seen some of this in previous lessons with with the Do Not Migrate option for fields and ability to provide field mapping descriptions. In this lesson we'll take a look at how we can make use of the additional tools to do things like; Show the name, contact info, and roles of individuals working on the migration, pose questions to other team members via the migration UI, and link individual field mappings to related tickets in our bug tracking software. Making it easier for team members who don't want to be involved with the code to help move our migration along.
In this lesson we'll continue to add field mappings to the basic migration class created in the previous lesson. We'll see how to add more information about the available source fields. We'll map more of the player source data fields to their equivalent destination fields and learn about some of the many ways that fields can be mapped. Finally we'll also cover mapping sub-fields which allows us to import data for things like the text format of a node's body field or the alt column in an image field. Information that's contained within a meta field.
In this week's lessons for the Importing Data With Migrate and Drupal 7 series we get a good look at our field mappings. This is the time that we make sure our source data is being properly handled and getting to the right destination fields in our Drupal site's database. We walk through basic field mapping, and see how that looks and works in the site UI, as well as with Drush. Then we explore different ways we can transform source data during the migration process, so that it matches what our destination field is expecting.
The entire Drupalize.Me team went to Prague, along with a number of other Lullabots, for DrupalCon Prague. In our latest podcast episode a few of us share what it was like, and the excitement and energy of new things on the horizon.