You are here

public function GameBaseball::__construct in Migrate 7.2

General initialization of a Migration object.

Overrides Migration::__construct

File

migrate_example_baseball/migrate_example_baseball.migrate.inc, line 30
A baseball game migration example.

Class

GameBaseball
A migration that is reused for each source CSV file.

Code

public function __construct($arguments) {
  parent::__construct($arguments);
  $this->description = t('Import box scores from CSV file.');

  // Create a map object for tracking the relationships between source rows
  $this->map = new MigrateSQLMap($this->machineName, array(
    'start_date' => array(
      'type' => 'varchar',
      'length' => 8,
      'not null' => TRUE,
      'description' => 'Start date',
    ),
    'home_team' => array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'description' => 'Home team',
    ),
    'home_game_number' => array(
      'type' => 'int',
      'not null' => TRUE,
      'description' => 'Home team game number',
    ),
  ), MigrateDestinationNode::getKeySchema());

  // Create a MigrateSource object, which manages retrieving the input data.
  $this->source = new MigrateSourceCSV($arguments['source_file'], $this
    ->csvcolumns(), array(), $this
    ->fields());
  $this->destination = new MigrateDestinationNode('migrate_example_baseball');
  $this
    ->addFieldMapping('title', 'title')
    ->description('See prepareRow().');
  $this
    ->addFieldMapping('field_start_date', 'start_date');
  $this
    ->addFieldMapping('field_park', 'park_id');
  $this
    ->addFieldMapping('field_visiting_team', 'visiting_team');
  $this
    ->addFieldMapping('field_home_team', 'home_team');
  $this
    ->addFieldMapping('field_home_game_number', 'home_game_number');
  $this
    ->addFieldMapping('field_home_score', 'home_score');
  $this
    ->addFieldMapping('field_visiting_score', 'visiting_score');
  $this
    ->addFieldMapping('field_outs', 'outs');
  $this
    ->addFieldMapping('field_attendance', 'attendance');
  $this
    ->addFieldMapping('field_duration', 'duration')
    ->defaultValue(NULL);
  $this
    ->addFieldMapping('field_home_pitcher', 'home_pitcher');
  $this
    ->addFieldMapping('field_visiting_pitcher', 'visiting_pitcher');
  $this
    ->addFieldMapping('field_home_batters', 'home_batters')
    ->separator(',')
    ->description('See prepareRow().');
  $this
    ->addFieldMapping('field_visiting_batters', 'visiting_batters')
    ->separator(',')
    ->description('See prepareRow().');
  for ($i = 1; $i <= 9; $i++) {
    $this
      ->addFieldMapping(NULL, "visiting_batter_{$i}")
      ->description('Not needed since we use the multi-value field: visiting_batters.');
    $this
      ->addFieldMapping(NULL, "home_batter_{$i}")
      ->description('Not needed since we use the multi-value field: home_batters.');
  }
}