You are here

public function WineRoleMigration::__construct in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 migrate_example/wine.inc \WineRoleMigration::__construct()

General initialization of a Migration object.

Overrides Migration::__construct

File

migrate_example/wine.inc, line 160
Advanced migration examples. These serve two purposes:

Class

WineRoleMigration

Code

public function __construct() {
  parent::__construct(MigrateGroup::getInstance('wine', array(
    'default',
  )));
  $this->description = t('XML feed (multi items) of roles (positions)');

  // TIP: Regular dependencies, besides enforcing (in the absence of --force)
  // the run order of migrations, affect the sorting of migrations on display.
  // You can use soft dependencies to affect just the display order when the
  // migrations aren't technically required to run in a certain order. In this
  // case, we want the role migration to appear after the file migration.
  $this->softDependencies = array(
    'WineBestWith',
  );

  // There isn't a consistent way to automatically identify appropriate "fields"
  // from an XML feed, so we pass an explicit list of source fields
  $fields = array(
    'name' => t('Position name'),
  );

  // The source ID here is the one retrieved from each data item in the XML file, and
  // used to identify specific items
  $this->map = new MigrateSQLMap($this->machineName, array(
    'sourceid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ),
  ), MigrateDestinationRole::getKeySchema());

  // IMPORTANT: Do not try this at home! We have included importable files
  // with the migrate_example module so it can be very simply installed and
  // run, but you should never include any data you want to keep private
  // (especially user data like email addresses, phone numbers, etc.) in the
  // module directory. Your source data should be outside of the webroot, and
  // should not be anywhere where it may get committed into a revision control
  // system.
  // This can also be an URL instead of a file path.
  $xml_folder = drupal_get_path('module', 'migrate_example') . '/xml/';
  $items_url = $xml_folder . 'positions.xml';
  $item_xpath = '/positions/position';

  // relative to document
  $item_ID_xpath = 'sourceid';

  // relative to item_xpath and gets assembled
  // into full path /producers/producer/sourceid
  $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
  $this->source = new MigrateSourceMultiItems($items_class, $fields);
  $this->destination = new MigrateDestinationRole();
  $this
    ->addFieldMapping('name', 'name')
    ->xpath('name');
  $this
    ->addUnmigratedDestinations(array(
    'weight',
  ));
}