You are here

public static function TemporaryTableMapping::getTempTableName in Drupal 8

Generates a temporary table name.

The method accounts for a maximum table name length of 64 characters.

Parameters

string $table_name: The initial table name.

string $prefix: (optional) The prefix to use for the new table name. Defaults to 'tmp_'.

Return value

string The final table name.

1 call to TemporaryTableMapping::getTempTableName()
TemporaryTableMapping::generateFieldTableName in core/lib/Drupal/Core/Entity/Sql/TemporaryTableMapping.php
Generates a safe and unambiguous field table name.

File

core/lib/Drupal/Core/Entity/Sql/TemporaryTableMapping.php, line 37

Class

TemporaryTableMapping
Defines a temporary table mapping class.

Namespace

Drupal\Core\Entity\Sql

Code

public static function getTempTableName($table_name, $prefix = 'tmp_') {
  $tmp_table_name = $prefix . $table_name;

  // Limit the string to 48 characters, keeping a 16 characters margin for db
  // prefixes.
  if (strlen($table_name) > 48) {
    $short_table_name = substr($table_name, 0, 34);
    $table_hash = substr(hash('sha256', $table_name), 0, 10);
    $tmp_table_name = $prefix . $short_table_name . $table_hash;
  }
  return $tmp_table_name;
}