You are here

protected function MigrationCreationTrait::getLegacyDrupalVersion in Migrate Upgrade 8

Determines what version of Drupal the source database contains.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection object.

Return value

int|FALSE An integer representing the major branch of Drupal core (e.g. '6' for Drupal 6.x), or FALSE if no valid version is matched.

1 call to MigrationCreationTrait::getLegacyDrupalVersion()
MigrationCreationTrait::getMigrationTemplates in src/MigrationCreationTrait.php
Sets up the relevant migrations for import from a database connection.

File

src/MigrationCreationTrait.php, line 184
Contains \Drupal\migrate_upgrade\MigrationCreationTrait.

Class

MigrationCreationTrait
Creates the appropriate migrations for a given source Drupal database.

Namespace

Drupal\migrate_upgrade

Code

protected function getLegacyDrupalVersion(Connection $connection) {

  // Don't assume because a table of that name exists, that it has the columns
  // we're querying. Catch exceptions and report that the source database is
  // not Drupal.
  // Drupal 5/6/7 can be detected by the schema_version in the system table.
  if ($connection
    ->schema()
    ->tableExists('system')) {
    try {
      $version_string = $connection
        ->query('SELECT schema_version FROM {system} WHERE name = :module', [
        ':module' => 'system',
      ])
        ->fetchField();
      if ($version_string && $version_string[0] == '1') {
        if ((int) $version_string >= 1000) {
          $version_string = '5';
        }
        else {
          $version_string = FALSE;
        }
      }
    } catch (\PDOException $e) {
      $version_string = FALSE;
    }
  }
  elseif ($connection
    ->schema()
    ->tableExists('key_value')) {
    $result = $connection
      ->query("SELECT value FROM {key_value} WHERE collection = :system_schema  and name = :module", [
      ':system_schema' => 'system.schema',
      ':module' => 'system',
    ])
      ->fetchField();
    $version_string = unserialize($result);
  }
  else {
    $version_string = FALSE;
  }
  return $version_string ? substr($version_string, 0, 1) : FALSE;
}