You are here

public function WineCommentMigration::__construct in Migrate 6.2

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

General initialization of a Migration object.

Overrides AdvancedExampleMigration::__construct

File

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

Class

WineCommentMigration

Code

public function __construct() {
  parent::__construct();
  $this->description = 'Comments about wines';
  $this->dependencies = array(
    'WineUser',
    'WineWine',
  );
  $this->map = new MigrateSQLMap($this->machineName, array(
    'commentid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ),
  ), MigrateDestinationComment::getKeySchema());
  $query = db_select('migrate_example_wine_comment', 'wc')
    ->fields('wc', array(
    'commentid',
    'comment_parent',
    'name',
    'mail',
    'accountid',
    'body',
    'wineid',
    'subject',
    'commenthost',
    'userpage',
    'posted',
    'lastchanged',
  ))
    ->orderBy('comment_parent');
  $this->source = new MigrateSourceSQL($query);
  $this->destination = new MigrateDestinationComment('comment_node_migrate_example_wine');

  // Mapped fields
  $this
    ->addSimpleMappings(array(
    'name',
    'subject',
    'mail',
  ));
  $this
    ->addFieldMapping('status')
    ->defaultValue(COMMENT_PUBLISHED);
  $this
    ->addFieldMapping('nid', 'wineid')
    ->sourceMigration('WineWine');
  $this
    ->addFieldMapping('uid', 'accountid')
    ->sourceMigration('WineUser')
    ->defaultValue(0);
  $this
    ->addFieldMapping('pid', 'comment_parent')
    ->sourceMigration('WineComment')
    ->description('Parent comment');
  $this
    ->addFieldMapping('comment', 'body');
  $this
    ->addFieldMapping('hostname', 'commenthost');
  $this
    ->addFieldMapping('timestamp', 'lastchanged');
  $this
    ->addFieldMapping('homepage', 'userpage');

  // No unmapped source fields
  // Unmapped destination fields
  $this
    ->addUnmigratedDestinations(array(
    'thread',
    'language',
  ));
}