Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297510

[Meta] Remove database specific logic from core

$
0
0

Problem/Motivation

Drupal core has still lots of database specific logic that has not been moved to DTBNG. There are many parts of core that take conditional actions depending on which database backend is being used:

$db_type = Database::getConnection()->databaseType();
    if (in_array($db_type, ['mysql', 'pgsql'])) {
      $offset = '+00:00';
      static $already_set = FALSE;
      if (!$already_set) {
        if ($db_type == 'pgsql') {
          Database::getConnection()->query("SET TIME ZONE INTERVAL '$offset' HOUR TO MINUTE");
        }
        elseif ($db_type == 'mysql') {
          Database::getConnection()->query("SET @@session.time_zone = '$offset'");
        }

        $already_set = TRUE;
      }
    }

This prevents contributed database drivers from being able to fully support Drupal, and completely defeats the purpose of having a Database Abstraction layer.

How much code is affected? Doing a quick find-in-files of "databaseType()":

...\lib\Drupal\Core\Command\DbDumpCommand.php(138): if ($connection->databaseType() !== 'mysql') {
...\modules\path\tests\src\Functional\PathAliasTest.php(103): if ($connection->databaseType() != 'sqlite') {
...\modules\path\tests\src\Functional\PathAliasTest.php(257): if ($connection->databaseType() != 'sqlite') {
...\modules\simpletest\src\Tests\KernelTestBaseTest.php(345): if ($connection->databaseType() != 'sqlite') {
...\modules\system\src\Tests\Entity\Update\LangcodeToAsciiUpdateTest.php(30): if (Database::getConnection()->databaseType() !== 'mysql') {
...\modules\system\tests\src\Kernel\Scripts\DbDumpCommandTest.php(29): if (Database::getConnection()->databaseType() !== 'mysql') {
...\modules\views\src\Plugin\views\argument\StringArgument.php(183): if (Database::getConnection()->databaseType() == 'sqlite') {
...\modules\views\src\Plugin\views\argument\StringArgument.php(189): if (Database::getConnection()->databaseType() == 'pgsql') {
...\modules\views\src\Plugin\views\argument\StringArgument.php(215): if ($this->options['case'] != 'none'&& Database::getConnection()->databaseType() == 'pgsql') {
...\modules\views\src\Plugin\views\argument\StringArgument.php(284): if ($this->options['case'] != 'none'&& Database::getConnection()->databaseType() == 'pgsql') {
...\modules\views\src\Plugin\views\query\Sql.php(1758): $db_type = Database::getConnection()->databaseType();
...\modules\views\src\Plugin\views\query\Sql.php(1796): $db_type = Database::getConnection()->databaseType();
...\modules\views\src\Plugin\views\query\Sql.php(1819): $db_type = Database::getConnection()->databaseType();
...\tests\Drupal\KernelTests\Core\Command\DbDumpTest.php(83): $this->skipTests = Database::getConnection()->databaseType() !== 'mysql';
...\tests\Drupal\KernelTests\Core\Database\ConnectionTest.php(125): if (Database::getConnection()->databaseType() !== 'mysql' || !defined('\PDO::MYSQL_ATTR_MULTI_STATEMENTS')) {
...\tests\Drupal\KernelTests\Core\Database\ConnectionTest.php(162): if (Database::getConnection()->databaseType() !== 'pgsql') {
...\tests\Drupal\KernelTests\Core\Database\SchemaTest.php(66): if (Database::getConnection()->databaseType() == 'mysql') {
...\tests\Drupal\KernelTests\Core\Database\SchemaTest.php(189): $db_type = Database::getConnection()->databaseType();
...\tests\Drupal\KernelTests\Core\Database\SchemaTest.php(266): if (Database::getConnection()->databaseType() != 'mysql') {
...\tests\Drupal\KernelTests\Core\Database\SchemaTest.php(430): if (Database::getConnection()->databaseType() == 'mysql') {
...\tests\Drupal\KernelTests\Core\Database\SchemaTest.php(838): $db_type = Database::getConnection()->databaseType();
...\tests\Drupal\KernelTests\Core\Database\SelectComplexTest.php(236): $db_type = Database::getConnection()->databaseType();
...\tests\Drupal\KernelTests\KernelTestBaseTest.php(226): if ($connection->databaseType() != 'sqlite') {
...\tests\Drupal\Tests\Core\Database\Stub\Connection.php(47): public function databaseType() {

The most offending of these all is the hardcoded date related management spread all over the Views component:

#2657888: Add Date function support in DTBNG

Proposed resolution

Remove any code in core that is in the form of:

   $db_type = Database::getConnection()->databaseType();
    if ($db_type == 'whatever') {
      // I'm not portable.
   }

Remaining tasks

Do it.

User interface changes

API changes

Data model changes


Viewing all articles
Browse latest Browse all 297510

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>