Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MigrationConfigurationTrait.php

function 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.

1 call to MigrationConfigurationTrait::getLegacyDrupalVersion()
CredentialForm::validateForm in core/modules/migrate_drupal_ui/src/Form/CredentialForm.php
Form validation handler.

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();
        } catch (DatabaseExceptionWrapper) {
            // All database errors return FALSE.
        }
    }
    return match (TRUE) {    !isset($version_string) => FALSE,
        (int) $version_string >= 6000 => substr($version_string, 0, 1),
        (int) $version_string >= 1000 => '5',
        default => FALSE,
    
    };
}
RSS feed
Powered by Drupal