The central class in the Migrate module - the one you'll spend most of your time dealing with - is the
Migration class. You will derive your own classes from
Migration, each of which will represent the migration of data from a given source (such as a query against a source database) to a given Drupal destination (such as nodes of a specific content type, like 'article').
You will embed in this class instances of four other classes:
MigrateSource: This class will encapsulate your source data.
- It implements the Iterable interface and can be iterated to retrieve source objects
- This means you can use it in a foreach loop, producing a single source data object for each iteration
- Example source classes are:
MigrateDestination: This class will encapsulate your destination object (user, node, etc.).
- As the Migration class loops over MigrateSource, it will pass the resulting data into the MigrateDestination object to be manipulated and saved to the Drupal database.
- Example destination classes are:
MigrateFieldMapping: This class represents a mapping between a source field and a destination field.
- A field mapping defines how a given destination field (such as a user's email address, or a node's title) will be determined from the source data. In its simplest form, a source field is simply copied to a destination field, but the field mapping object supports setting default values and defining various ways to manipulate the data value along the way.
- The following image shows how
MigrateMap: This class represents the relationship between source and destination objects.
- An important feature of the Migrate module is the maintenance of relationships between each source object read by MigrateSource, and the resulting Drupal object written by MigrateDestination. MigrateMap is responsible for keeping track of this relationship, by storing the primary keys of the source and the destination in a map table it maintains.
- Most migrations use the
MigrateSQLMapthat tracks the relations in the database.
This architecture summarize how these classes interplay: The Migrate class contains a source and destination class. The field mappings define the relation between the source and destination fields, while the MigrateMap does the bookkeeping.