Commit 20e4baee authored by catch's avatar catch
Browse files

Issue #3257201 by murilohp, ravi.shankar, beatrizrodrigues, daffie, mondrake:...

Issue #3257201 by murilohp, ravi.shankar, beatrizrodrigues, daffie, mondrake: Create the new method Drupal\Core\Database\Connection::getPrefix() and deprecate Drupal\Core\Database\Connection::prefixTable($table)
parent 3d682d17
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -363,6 +363,15 @@ public function getConnectionOptions() {
  public function attachDatabase(string $database): void {
  }

  /**
   * Returns the prefix of the tables.
   *
   * @return string $prefix
   */
  public function getPrefix(): string {
    return $this->prefix;
  }

  /**
   * Set the prefix used by this database connection.
   *
@@ -428,8 +437,14 @@ public function quoteIdentifiers($sql) {
   *
   * @param string $table
   *   (optional) The table to find the prefix for.
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0.
   * Instead, you should just use Connection::getPrefix().
   *
   * @see https://www.drupal.org/node/3260849
   */
  public function tablePrefix($table = 'default') {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Instead, you should just use Connection::getPrefix(). See https://www.drupal.org/node/3260849', E_USER_DEPRECATED);
    return $this->prefix;
  }

@@ -460,7 +475,7 @@ public function getUnprefixedTablesMap() {
   */
  public function getFullQualifiedTableName($table) {
    $options = $this->getConnectionOptions();
    $prefix = $this->tablePrefix($table);
    $prefix = $this->getPrefix();
    return $options['database'] . '.' . $prefix . $table;
  }

+2 −2
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public function nextPlaceholder() {
  protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) {
    $info = [
      'schema' => $this->defaultSchema,
      'prefix' => $this->connection->tablePrefix($table),
      'prefix' => $this->connection->getPrefix(),
    ];
    if ($add_prefix) {
      $table = $info['prefix'] . $table;
@@ -196,7 +196,7 @@ public function findTables($table_expression) {
    $condition = $this->buildTableNameCondition('%', 'LIKE');
    $condition->compile($this->connection, $this);

    $prefix = $this->connection->tablePrefix();
    $prefix = $this->connection->getPrefix();
    $prefix_length = strlen($prefix);
    $tables = [];
    // Normally, we would heartily discourage the use of string
+1 −1
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition

    // Default generated table names, limited to 63 characters.
    $machine_name = str_replace(':', '__', $this->migration->id());
    $prefix_length = strlen($this->database->tablePrefix());
    $prefix_length = strlen($this->database->getPrefix());
    $this->mapTableName = 'migrate_map_' . mb_strtolower($machine_name);
    $this->mapTableName = mb_substr($this->mapTableName, 0, 63 - $prefix_length);
    $this->messageTableName = 'migrate_message_' . mb_strtolower($machine_name);
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class Schema extends DatabaseSchema {
   *   A keyed array with information about the database, table name and prefix.
   */
  protected function getPrefixInfo($table = 'default', $add_prefix = TRUE) {
    $info = ['prefix' => $this->connection->tablePrefix($table)];
    $info = ['prefix' => $this->connection->getPrefix()];
    if ($add_prefix) {
      $table = $info['prefix'] . $table;
    }
+1 −1
Original line number Diff line number Diff line
@@ -299,7 +299,7 @@ public function nextId($existing = 0) {
   */
  public function getFullQualifiedTableName($table) {
    $options = $this->getConnectionOptions();
    $prefix = $this->tablePrefix($table);
    $prefix = $this->getPrefix();

    // The fully qualified table name in PostgreSQL is in the form of
    // <database>.<schema>.<table>, so we have to include the 'public' schema in
Loading