You are here

public function MigrateSQLMap::__construct in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/sources/sqlmap.inc \MigrateSQLMap::__construct()

Constructor.

Parameters

string $machine_name: The unique reference to the migration that we are mapping.

array $source_key: The database schema for the source key.

array $destination_key: The database schema for the destination key.

string $connection_key: Optional - The connection used to create the mapping tables. By default this is the destination (Drupal). If it's not possible to make joins between the destination database and your source database you can specify a different connection to create the mapping tables on.

array $options: Optional - Options applied to this source.

File

plugins/sources/sqlmap.inc, line 106
Defines a Drupal db-based implementation of MigrateMap.

Class

MigrateSQLMap
@file Defines a Drupal db-based implementation of MigrateMap.

Code

public function __construct($machine_name, array $source_key, array $destination_key, $connection_key = 'default', $options = array()) {
  if (isset($options['track_last_imported'])) {
    $this->trackLastImported = TRUE;
  }
  if (isset($options['cache_map_lookups'])) {
    $this->cacheMapLookups = $options['cache_map_lookups'];
  }
  else {
    $this->cacheMapLookups = FALSE;
  }
  $this->connection = Database::getConnection('default', $connection_key);

  // Default generated table names, limited to 63 characters.
  $prefixLength = strlen($this->connection
    ->tablePrefix());
  $this->mapTable = 'migrate_map_' . drupal_strtolower($machine_name);
  $this->mapTable = drupal_substr($this->mapTable, 0, 63 - $prefixLength);
  $this->messageTable = 'migrate_message_' . drupal_strtolower($machine_name);
  $this->messageTable = drupal_substr($this->messageTable, 0, 63 - $prefixLength);
  $this->sourceKey = $source_key;
  $this->destinationKey = $destination_key;

  // Build the source and destination key maps.
  $this->sourceKeyMap = array();
  $count = 1;
  foreach ($source_key as $field => $schema) {
    $this->sourceKeyMap[$field] = 'sourceid' . $count++;
  }
  $this->destinationKeyMap = array();
  $count = 1;
  foreach ($destination_key as $field => $schema) {
    $this->destinationKeyMap[$field] = 'destid' . $count++;
  }
  $this
    ->ensureTables();
}