Last updated July 5, 2011. Created by mikeryan on May 9, 2011.
Log in to edit this page.

In some cases the items being imported may be conglomerated (as in an XML feed, where a single retrieval contains many items). In these cases, MigrateSourceMultiItems may be the right choice to represent the source data.

The subordinate MigrateItems class operates much like a fusion of MigrateList and MigrateItem. To define a MigrateItems class for a particular type of source, you need to implement the following methods:

__toString()

Should return a string representing the source of the ID (e.g., the URL of an XML feed).

getIdList()

Should return an array of the IDs available from the source.

computeCount()

Should return a count of the IDs available from the source.

getItem($id)

Given an ID obtained getIdList(), returns the data for the source item keyed by that ID, as an object.

MigrateSourceMultiItems

The MigrateSourceMultiItems class wraps around you MigrateItems object. In your migration constructor, construct a MigrateItems instance, and pass it the MigrateSourceList constructor (you may optionally also pass a source field list and an options array). The MigrateSourceMultiItems instance you create will then iterate over the IDs returned by getIdList(), passing each one to getItem() to obtain source data to be migrated.

See XML-based sources for an example of using these classes in your migration.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

The final paragraph on this page under subhead "MigrateSourceMultiItems" is unclear:

The MigrateSourceMultiItems class wraps around you MigrateItems object.

What does "wraps around" mean?

In your migration constructor, construct a MigrateItems instance, and pass it the MigrateSourceList constructor (you may optionally also pass a source field list and an options array).

What does it mean to "pass the MigrateSourceList constructor" to a MigrateItems instance? How do you "pass" a constructor to an instance of some other class? And does this mean a MigrateItems and MigrateSourceList object are both necessary to create a MigrateSourceMultiItems instance?

The MigrateSourceMultiItems instance you create will then iterate over the IDs returned by getIdList(), passing each one to getItem() to obtain source data to be migrated.

When does this iteration happen? Upon construction of the MigrateSourceMultiItems instance, or during the actual migration?

----------------
IT consultant, web designer, writer and researcher
http://www.sheldonrampton.com/portfolio