You are here

public function MigrateSourceSQL::__construct in Migrate 7.2

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

Simple initialization.

Parameters

SelectQueryInterface $query: The query we are iterating over.

array $fields: Optional - keys are field names, values are descriptions. Use to override the default descriptions, or to add additional source fields which the migration will add via other means (e.g., prepareRow()).

SelectQueryInterface $count_query: Optional - an explicit count query, primarily used when counting the primary query is slow.

boolean $options: Options applied to this source.

Overrides MigrateSource::__construct

File

plugins/sources/sql.inc, line 126
Define a MigrateSource for importing from Drupal connections.

Class

MigrateSourceSQL
Implementation of MigrateSource, to handle imports from Drupal connections.

Code

public function __construct(SelectQueryInterface $query, array $fields = array(), SelectQueryInterface $count_query = NULL, array $options = array()) {
  parent::__construct($options);
  $this->originalQuery = $query;
  $this->query = clone $query;
  $this->fields = $fields;
  if (is_null($count_query)) {
    $this->countQuery = clone $query
      ->countQuery();
  }
  else {
    $this->countQuery = $count_query;
  }
  if (isset($options['batch_size'])) {
    $this->batchSize = $options['batch_size'];

    // Joining to the map table is incompatible with batching, disable it.
    $options['map_joinable'] = FALSE;
  }

  // If we're tracking changes, then we need to fetch all rows to see if
  // they've changed, we can't make that determination through a direct join.
  if (!empty($options['track_changes'])) {
    $options['map_joinable'] = FALSE;
  }
  if (isset($options['map_joinable'])) {
    $this->mapJoinable = $options['map_joinable'];
  }
  else {

    // TODO: We want to automatically determine if the map table can be joined
    // directly to the query, but this won't work unless/until
    // http://drupal.org/node/802514 is committed, assume joinable for now
    $this->mapJoinable = TRUE;

    /*      // To be able to join the map directly, it must be a PDO map on the same
                // connection, or a compatible connection
                $map = $migration->getMap();
                if (is_a($map, 'MigrateSQLMap')) {
                  $map_options = $map->getConnection()->getConnectionOptions();
                  $query_options = $this->query->connection()->getConnectionOptions();

                  // Identical options means it will work
                  if ($map_options == $query_options) {
                    $this->mapJoinable = TRUE;
                  }
                  else {
                    // Otherwise, the one scenario we know will work is if it's MySQL and
                    // the credentials match (SQLite too?)
                    if ($map_options['driver'] == 'mysql' && $query_options['driver'] == 'mysql') {
                      if ($map_options['host'] == $query_options['host'] &&
                          $map_options['port'] == $query_options['port'] &&
                          $map_options['username'] == $query_options['username'] &&
                          $map_options['password'] == $query_options['password']) {
                        $this->mapJoinable = TRUE;
                      }
                    }
                  }
                }*/
  }
}