Community Documentation

Source classes

Last updated December 19, 2012. Created by mikeryan on December 24, 2010.
Edited by drewish. Log in to edit this page.

The Migrate module uses classes derived from the abstract class MigrateSource to encapsulate source data to be imported. In a Migration class constructor, there must be a call like:

<?php
$this
->source = new MigrateSourceSQL($query);
?>

An instance of a MigrateSource class (with appropriate arguments to indicate where the data is coming from) must be created and assigned to $this->source.

In this section, we examine the sources that are bundled with Migrate, and explain how to create your own source class.

All sources accept an array of options for modifying their default behavior. One option is supported by all source classes - cache_counts. If you set this option to TRUE:

<?php
$this
->source = new MigrateSourceSQL($query, array(), NULL, array('cache_counts' => TRUE);
?>

then the count of total records available from the source will be cached. That is, it will only be actually computed directly from the source if it has never been obtained before, if the Drupal default cache has been cleared, or you pass the --refresh option to the drush migrate-status command. This is quite useful in cases where obtaining the count is slow (such as from a large XML feed).

The skip_count option allows you to disable counting entirely, when for example the cost of counting is so high you don't want to do it even once.

The cache_key option specifies the name of the cache key for the count - the default value is an md5 of the concrete source class string value (__toString), which might in some cases be duplicated for multiple source classes derived from a common ancestor.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Programmers

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