Community Documentation

Migrate module architecture

Last updated September 15, 2012. Created by mikeryan on April 11, 2012.
Edited by loopduplicate, scor, prakashp, twom. Log in to edit this page.

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: MigrateSourceSQL, MigrateSourceCSV, MigrateSourceJSON, MigrateSourceOracle, MigrateSourceList, ...

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: MigrateDestinationUser, MigrateDestinationTerm, MigrateDestinationNode, MigrateDestinationFile, MigrateDestinationComment, ...

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 MigrateSQLMap that tracks the relations in the database.

Migrate module architecture
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.

AttachmentSize
architecture.png37.47 KB

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Programmers
Level
Intermediate
Keywords
migrate

Administration & Security Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here