You are here

protected function SqlBase::mapJoinable in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::mapJoinable()
  2. 9 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::mapJoinable()

Checks if we can join against the map table.

This function specifically catches issues when we're migrating with unique sets of credentials for the source and destination database.

Return value

bool TRUE if we can join against the map table otherwise FALSE.

2 calls to SqlBase::mapJoinable()
SqlBase::initializeIterator in core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
Initializes the iterator with the source data.
TestSqlBase::mapJoinable in core/modules/migrate/tests/src/Unit/SqlBaseTest.php
Checks if we can join against the map table.
1 method overrides SqlBase::mapJoinable()
TestSqlBase::mapJoinable in core/modules/migrate/tests/src/Unit/SqlBaseTest.php
Checks if we can join against the map table.

File

core/modules/migrate/src/Plugin/migrate/source/SqlBase.php, line 400

Class

SqlBase
Sources whose data may be fetched via a database connection.

Namespace

Drupal\migrate\Plugin\migrate\source

Code

protected function mapJoinable() {

  // Do not join map if explicitly configured not to.
  if (isset($this->configuration['ignore_map']) && $this->configuration['ignore_map']) {
    return FALSE;
  }

  // If we are using high water, but haven't yet set a high water mark, do not
  // join the map table, as we want to get all available records.
  if ($this
    ->getHighWaterProperty() && $this
    ->getHighWater() === NULL) {
    return FALSE;
  }

  // If we are tracking changes, we also need to retrieve all rows to compare
  // hashes
  if ($this->trackChanges) {
    return FALSE;
  }
  if (!$this
    ->getIds()) {
    return FALSE;
  }

  // With batching, we want a later batch to return the same rows that would
  // have been returned at the same point within a monolithic query. If we
  // join to the map table, the first batch is writing to the map table and
  // thus affecting the results of subsequent batches. To be safe, we avoid
  // joining to the map table when batching.
  if ($this->batchSize > 0) {
    return FALSE;
  }
  $id_map = $this->migration
    ->getIdMap();
  if (!$id_map instanceof Sql) {
    return FALSE;
  }
  $id_map_database_options = $id_map
    ->getDatabase()
    ->getConnectionOptions();
  $source_database_options = $this
    ->getDatabase()
    ->getConnectionOptions();

  // Special handling for sqlite which deals with files.
  if ($id_map_database_options['driver'] === 'sqlite' && $source_database_options['driver'] === 'sqlite' && $id_map_database_options['database'] != $source_database_options['database']) {
    return FALSE;
  }

  // FALSE if driver is PostgreSQL and database doesn't match.
  if ($id_map_database_options['driver'] === 'pgsql' && $source_database_options['driver'] === 'pgsql' && $id_map_database_options['database'] != $source_database_options['database']) {
    return FALSE;
  }
  foreach ([
    'username',
    'password',
    'host',
    'port',
    'namespace',
    'driver',
  ] as $key) {
    if (isset($source_database_options[$key]) && isset($id_map_database_options[$key])) {
      if ($id_map_database_options[$key] != $source_database_options[$key]) {
        return FALSE;
      }
    }
  }
  return TRUE;
}