You are here

public static function MigrationConfigurationTrait::getLegacyDrupalVersion in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/src/MigrationConfigurationTrait.php \Drupal\migrate_drupal\MigrationConfigurationTrait::getLegacyDrupalVersion()

Determines what version of Drupal the source database contains.

Parameters

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

Return value

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

6 calls to MigrationConfigurationTrait::getLegacyDrupalVersion()
CredentialForm::validateForm in core/modules/migrate_drupal_ui/src/Form/CredentialForm.php
Form validation handler.
CredentialFormTest::getSourceBasePath in core/modules/migrate_drupal_ui/tests/src/Functional/CredentialFormTest.php
Gets the source base path for the concrete test.
MigrateUpgradeTestBase::assertUpgrade in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php
Asserts the upgrade completed successfully.
MigrateUpgradeTestBase::getCredentials in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php
Creates an array of credentials for the Credential form.
migrate_drupal_migration_plugins_alter in core/modules/migrate_drupal/migrate_drupal.module
Implements hook_migration_plugins_alter().

... See full list

File

core/modules/migrate_drupal/src/MigrationConfigurationTrait.php, line 204

Class

MigrationConfigurationTrait
Configures the appropriate migrations for a given source Drupal database.

Namespace

Drupal\migrate_drupal

Code

public static 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')) {
    try {
      $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);
    } catch (DatabaseExceptionWrapper $e) {
      $version_string = FALSE;
    }
  }
  else {
    $version_string = FALSE;
  }
  return $version_string ? substr($version_string, 0, 1) : FALSE;
}