You are here

public function BeerCommentMigration::__construct in Migrate 6.2

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

General initialization of a Migration object.

Overrides BasicExampleMigration::__construct

File

migrate_example/beer.inc, line 355
A basic example of using the Migrate module to import taxonomy, users, nodes, and comments.

Class

BeerCommentMigration
Import items from the migrate_example_beer_comment table and make them into Drupal comment objects.

Code

public function __construct() {
  parent::__construct();
  $this->description = 'Comments about beers';
  $this->dependencies = array(
    'BeerUser',
    'BeerNode',
  );
  $this->map = new MigrateSQLMap($this->machineName, array(
    'cid' => array(
      'type' => 'int',
      'not null' => TRUE,
    ),
  ), MigrateDestinationComment::getKeySchema());
  $query = db_select('migrate_example_beer_comment', 'mec')
    ->fields('mec', array(
    'cid',
    'cid_parent',
    'name',
    'mail',
    'aid',
    'body',
    'bid',
    'subject',
  ))
    ->orderBy('cid_parent', 'ASC');
  $this->source = new MigrateSourceSQL($query);
  $this->destination = new MigrateDestinationComment('comment_node_migrate_example_beer');

  // Mapped fields
  $this
    ->addSimpleMappings(array(
    'name',
    'subject',
    'mail',
  ));
  $this
    ->addFieldMapping('status')
    ->defaultValue(COMMENT_PUBLISHED);

  // Map the incoming beer ID to the resulting Drupal nid
  $this
    ->addFieldMapping('nid', 'bid')
    ->sourceMigration('BeerNode');
  $this
    ->addFieldMapping('uid', 'aid')
    ->sourceMigration('BeerUser')
    ->defaultValue(0);
  $this
    ->addFieldMapping('pid', 'cid_parent')
    ->sourceMigration('BeerComment')
    ->description('Parent comment.');
  $this
    ->addFieldMapping('comment', 'body');

  // No unmapped source fields
  // Unmapped destination fields
  $this
    ->addUnmigratedDestinations(array(
    'user_name',
    'user_email',
    'hostname',
    'created',
    'changed',
    'thread',
    'homepage',
    'language',
  ));
}