class TemporaryTableMapping

Defines a temporary table mapping class.

Hierarchy

Expanded class hierarchy of TemporaryTableMapping

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use the default table mapping with a prefix instead.

1 file declares its use of TemporaryTableMapping
DefaultTableMappingTest.php in core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php

File

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

Namespace

Drupal\Core\Entity\Sql
View source
class TemporaryTableMapping extends DefaultTableMapping {
  
  /**
   * {@inheritdoc}
   */
  protected function generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, $revision) {
    return static::getTempTableName(parent::generateFieldTableName($storage_definition, $revision));
  }
  
  /**
   * Generates a temporary table name.
   *
   * The method accounts for a maximum table name length of 64 characters.
   *
   * @param string $table_name
   *   The initial table name.
   * @param string $prefix
   *   (optional) The prefix to use for the new table name. Defaults to 'tmp_'.
   *
   * @return string
   *   The final table name.
   */
  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;
  }

}

Members

Title Sort descending Modifiers Object type Summary
TemporaryTableMapping::generateFieldTableName protected function
TemporaryTableMapping::getTempTableName public static function Generates a temporary table name.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.