You are here

public function WineProducerMigration::__construct in Migrate 6.2

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

General initialization of a Migration object.

Overrides AdvancedExampleMigration::__construct

File

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

Class

WineProducerMigration

Code

public function __construct() {
  parent::__construct();
  $this->description = t('Wine producers of the world');
  $this->dependencies = array(
    'WineRegion',
    'WineUser',
  );
  $this->map = new MigrateSQLMap($this->machineName, array(
    'producerid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'alias' => 'p',
    ),
  ), MigrateDestinationNode::getKeySchema());
  $query = db_select('migrate_example_wine_producer', 'p')
    ->fields('p', array(
    'producerid',
    'name',
    'body',
    'excerpt',
    'accountid',
  ));

  // Region term is singletons, handled straighforwardly
  $query
    ->leftJoin('migrate_example_wine_category_producer', 'reg', "p.producerid = reg.producerid");
  $query
    ->addField('reg', 'categoryid', 'region');
  $this->source = new MigrateSourceSQL($query);
  $this->destination = new MigrateDestinationNode('migrate_example_producer');

  // Mapped fields
  $this
    ->addFieldMapping('title', 'name')
    ->description(t('Mapping producer name in source to node title'));
  $this
    ->addFieldMapping('uid', 'accountid')
    ->sourceMigration('WineUser')
    ->defaultValue(1);
  $this
    ->addFieldMapping('Migrate Example Wine Regions', 'region')
    ->sourceMigration('WineRegion')
    ->arguments(array(
    'source_type' => 'tid',
  ));
  $this
    ->addFieldMapping('body', 'body');
  $this
    ->addFieldMapping('teaser', 'excerpt');
  $this
    ->addFieldMapping('sticky')
    ->defaultValue(0);

  // No unmapped source fields
  // Unmapped destination fields
  $this
    ->addUnmigratedDestinations(array(
    'is_new',
    'name',
    'created',
    'changed',
    'status',
    'promote',
    'revision',
    'language',
  ));
}