Verified Commit 4365ab3f authored by Dave Long's avatar Dave Long
Browse files

Issue #3221101 by mondrake, daffie, longwave: Deprecate...

Issue #3221101 by mondrake, daffie, longwave: Deprecate Drupal\Core\Database\Connection::makeSequenceName(), make it internal to PostgreSQL
parent 6e8cab81
Loading
Loading
Loading
Loading
+6 −0
Changes for core/lib/Drupal/Core/Database/Connection.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -668,8 +668,14 @@ public function getLogger() {
   *
   * @return string
   *   A table prefix-parsed string for the sequence name.
   *
   * @deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is
   *   no replacement.
   *
   * @see https://www.drupal.org/node/3377046
   */
  public function makeSequenceName($table, $field) {
    @trigger_error(__METHOD__ . "() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3377046", E_USER_DEPRECATED);
    $sequence_name = $this->prefixTables('{' . $table . '}_' . $field . '_seq');
    // Remove identifier quotes as we are constructing a new name from a
    // prefixed and quoted table name.
+10 −0
Changes for core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -21,4 +21,14 @@ public function testMultipleStatementsForNewPhp(): void {
    Database::getConnection('default', 'default')->query('SELECT * FROM {test}; SELECT * FROM {test_people}', [], ['allow_delimiter_in_query' => TRUE]);
  }

  /**
   * Tests deprecation of ::makeSequenceName().
   *
   * @group legacy
   */
  public function testMakeSequenceNameDeprecation(): void {
    $this->expectDeprecation("Drupal\\Core\\Database\\Connection::makeSequenceName() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3377046");
    $this->assertIsString($this->connection->makeSequenceName('foo', 'bar'));
  }

}
+22 −0
Changes for core/modules/pgsql/src/Driver/Database/pgsql/Connection.php: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -294,6 +294,28 @@ public function mapConditionOperator($operator) {
    return static::$postgresqlConditionOperatorMap[$operator] ?? NULL;
  }

  /**
   * Creates the appropriate sequence name for a given table and serial field.
   *
   * This method should only be called by the driver's code.
   *
   * @param string $table
   *   The table name to use for the sequence.
   * @param string $field
   *   The field name to use for the sequence.
   *
   * @return string
   *   A table prefix-parsed string for the sequence name.
   *
   * @internal
   */
  public function makeSequenceName($table, $field) {
    $sequence_name = $this->prefixTables('{' . $table . '}_' . $field . '_seq');
    // Remove identifier quotes as we are constructing a new name from a
    // prefixed and quoted table name.
    return str_replace($this->identifierQuotes, '', $sequence_name);
  }

  /**
   * Retrieve a the next id in a sequence.
   *
+1 −1
Changes for core/modules/pgsql/src/Update10101.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ public function getSequenceName(string $table, string $column): ?string {
   * @return bool
   *   TRUE if the sequence exists by the name.
   *
   * @see \Drupal\Core\Database\Connection::makeSequenceName()
   * @see \Drupal\pgsql\Driver\Database\pgsql\Connection::makeSequenceName()
   */
  private function sequenceExists(string $name): bool {
    return (bool) \Drupal::database()
+26 −0
Changes for core/modules/sqlite/tests/src/Kernel/sqlite/ConnectionTest.php: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\sqlite\Kernel\sqlite;

use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;

/**
 * SQLite-specific connection tests.
 *
 * @group Database
 */
class ConnectionTest extends DriverSpecificDatabaseTestBase {

  /**
   * Tests deprecation of ::makeSequenceName().
   *
   * @group legacy
   */
  public function testMakeSequenceNameDeprecation(): void {
    $this->expectDeprecation("Drupal\\Core\\Database\\Connection::makeSequenceName() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3377046");
    $this->assertIsString($this->connection->makeSequenceName('foo', 'bar'));
  }

}