Commit 5730ee6d authored by catch's avatar catch
Browse files

Issue #3123461 by daffie, Kristen Pol, alexpott, xjm: Deprecate support for...

Issue #3123461 by daffie, Kristen Pol, alexpott, xjm: Deprecate support for database drivers placed in DRUPAL_ROOT/drivers
parent 661d8a83
Loading
Loading
Loading
Loading
+7 −0
Changes for core/lib/Drupal/Core/Database/Connection.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -214,6 +214,7 @@ public function __construct(\PDO $connection, array $connection_options) {
      @trigger_error('In drupal:10.0.0 not setting the $identifierQuotes property in the concrete Connection class will result in an RuntimeException. See https://www.drupal.org/node/2986894', E_USER_DEPRECATED);
      $this->identifierQuotes = ['', ''];
    }

    assert(count($this->identifierQuotes) === 2 && Inspector::assertAllStrings($this->identifierQuotes), '\Drupal\Core\Database\Connection::$identifierQuotes must contain 2 string values');
    // The 'transactions' option is deprecated.
    if (isset($connection_options['transactions'])) {
@@ -228,6 +229,12 @@ public function __construct(\PDO $connection, array $connection_options) {
      $connection_options['namespace'] = (new \ReflectionObject($this))->getNamespaceName();
    }

    // The support for database drivers where the namespace that starts with
    // Drupal\\Driver\\Database\\ is deprecated.
    if (strpos($connection_options['namespace'], 'Drupal\Driver\Database') === 0) {
      @trigger_error('Support for database drivers located in the "drivers/lib/Drupal/Driver/Database" directory is deprecated in drupal:9.1.0 and is removed in drupal:10.0.0. Contributed and custom database drivers should be provided by modules and use the namespace "Drupal\MODULE_NAME\Driver\Database\DRIVER_NAME". See https://www.drupal.org/node/3123251', E_USER_DEPRECATED);
    }

    // Initialize and prepare the connection prefix.
    $this->setPrefix(isset($connection_options['prefix']) ? $connection_options['prefix'] : '');

+1 −1
Changes for core/tests/Drupal/Tests/Core/Database/ConditionTest.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public function testContribCondition() {
      ->setConstructorArgs([NULL])
      ->disableOriginalConstructor()
      ->getMock();
    $contrib_namespace = 'Drupal\Driver\Database\mock';
    $contrib_namespace = 'Drupal\mock\Driver\Database\mock';
    $mocked_namespace = $contrib_namespace . '\\Condition';
    class_alias('MockCondition', $mocked_namespace);

+13 −0
Changes for core/tests/Drupal/Tests/Core/Database/ConnectionTest.php: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -671,4 +671,17 @@ public function provideQueriesToTrim() {
    ];
  }

  /**
   * Tests the deprecation of Drupal 8 style database drivers.
   *
   * @group legacy
   * @expectedDeprecation Support for database drivers located in the "drivers/lib/Drupal/Driver/Database" directory is deprecated in drupal:9.1.0 and is removed in drupal:10.0.0. Contributed and custom database drivers should be provided by modules and use the namespace "Drupal\MODULE_NAME\Driver\Database\DRIVER_NAME". See https://www.drupal.org/node/3123251
   */
  public function testLegacyDatabaseDriverInRootDriversDirectory() {
    $namespace = 'Drupal\\Driver\\Database\\Stub';
    $mock_pdo = $this->createMock(StubPDO::class);
    $connection = new StubConnection($mock_pdo, ['namespace' => $namespace], ['"', '"']);
    $this->assertEquals($namespace, $connection->getConnectionOptions()['namespace']);
  }

}