You are here

public function MigrateSourceSQL::__construct in Migrate 6.2

Same name and namespace in other branches
  1. 7.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

1 call to MigrateSourceSQL::__construct()
MigrateSourceView::__construct in plugins/sources/view.inc
Simple initialization.
1 method overrides MigrateSourceSQL::__construct()
MigrateSourceView::__construct in plugins/sources/view.inc
Simple initialization.

File

plugins/sources/sql.inc, line 97
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['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;
                }
              }
            }
          }*/
  }
}