Migrate Module
An introduction that hopefully won't make you run in fear!
About the Migrate Module
What is the Migrate Module
- Collects data from external Datasources
- Databases
- External Feeds
- Files
- Alters the data
- Maps data with entity fields
- Creates Entities (typically Nodes)
- Can handle file fields for images and documents
- Can also handle entity references
Uses
- One time migrate from a legacy CMS
- Scheduled imports of external data feeds
- Advanced replacement for Feeds Module
- Load flat files to update entities
- Ex. External business systems that don't have an API
Cool Features
- Drush-able (recommended)
- Rollbacks
- Data manipulation
- Dependency Hierarchy
Building the Migration
The Basics
- Migrations need to be in their own custom module (can be a feature)
- The .module file will be empty
- A [module_name].migrate.inc file is needed to hold the migration meta data
- This file only contains a hook_migrate_api()
- A .inc file for each migration contains a class which extends the Migration abstract class. This holds all of the mappings and logic.
HOLD UP!
This sounds like OO
I thought this was a Drupal module!
Anyone need a quick crash course on Class inheritance?
(I.e. Abstract classes and extending them)
Architecture
-
MigrateSource
represents the source data. The Migration class iterates over row objects generated by this class.
- MigrateDestination represents the destination object (user, node, etc.). Each row produced by MigrateSource is manipulated and passed on to the destination class to create the object.
- MigrateMap represents the relationship between source and destination objects, keeping track of precisely which source data record resulted in the creation of which Drupal object.
- MigrateFieldMapping represents a mapping between a source field and a destination field.
Class Inheritance
Classes
Properties and Methods
Example:
class ToyotaCorolla {
public $color; // <-------- Properties
public $doors; // <----/
public function honk() { // <---- Method
print "beep, beep!";
}
}
$myCar = new ToyotaCorolla(); // Create a new instance of our class
$myCar->honk(); // "beep, beep"
Extending Classes
Uses the properties and methods of the existing class but now we can override or add to them.
class DamagedToyotaCorolla extends ToyotaCorolla { // Inherit everything
// Already have the $color and $doors properties
public function honk() { // Override the honk method
print "beep, clunk";
}
{
$myCar = new DamagedToyotaCorolla(); // Create a new instance of our class
$myCar->honk(); // "beep, clunk"
Let's Build a Migration
Useful Stuff
Migrate Doc: https://drupal.org/node/415260
Migrate Module
By akoebbe
Migrate Module
- 1,465