You are here

public function WineUpdatesMigration::__construct in Migrate 6.2

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

General initialization of a Migration object.

Overrides AdvancedExampleMigration::__construct

File

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

Class

WineUpdatesMigration
TIP: This demonstrates a migration designed not to import new content, but to update existing content (in this case, revised wine ratings)

Code

public function __construct() {
  parent::__construct();
  $this->description = t('Update wine ratings');
  $this->dependencies = array(
    'WineWine',
  );
  $this->softDependencies = array(
    'WineFinish',
  );
  $this->map = new MigrateSQLMap($this->machineName, array(
    'wineid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'description' => 'Wine ID',
      'alias' => 'w',
    ),
  ), MigrateDestinationNode::getKeySchema());
  $query = db_select('migrate_example_wine_updates', 'w')
    ->fields('w', array(
    'wineid',
    'rating',
  ));
  $this->source = new MigrateSourceSQL($query);
  $this->destination = new MigrateDestinationNode('migrate_example_wine');

  // Indicate we're updating existing data. The default, Migration::SOURCE, would
  // cause existing nodes to be completely replaced by the source data. In this
  // case, the existing node will be loaded and only the rating altered.
  $this->systemOfRecord = Migration::DESTINATION;

  // Mapped fields
  // The destination handler needs the nid to change - since the incoming data
  // has a source id, not a nid, we need to apply the original wine migration
  // mapping to populate the nid.
  $this
    ->addFieldMapping('nid', 'wineid')
    ->sourceMigration('WineWine');
  $this
    ->addFieldMapping('field_migrate_example_wine_ratin', 'rating');

  // No unmapped source fields
  // Unmapped destination fields
  $this
    ->addFieldMapping('uid');
  $this
    ->addFieldMapping('migrate_example_wine_varieties');
  $this
    ->addFieldMapping('migrate_example_wine_regions');
  $this
    ->addFieldMapping('migrate_example_wine_best_with');
  $this
    ->addFieldMapping('body');
  $this
    ->addFieldMapping('field_migrate_example_image');
  $this
    ->addFieldMapping('sticky');
  $this
    ->addFieldMapping('created');
  $this
    ->addFieldMapping('changed');
  $this
    ->addUnmigratedDestinations(array(
    'is_new',
    'status',
    'promote',
    'revision',
    'language',
  ));
}