3 namespace Drupal\Core\Entity\Sql;
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8 * Defines a temporary table mapping class.
10 class TemporaryTableMapping extends DefaultTableMapping {
15 protected function generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, $revision) {
16 return static::getTempTableName(parent::generateFieldTableName($storage_definition, $revision));
20 * Generates a temporary table name.
22 * The method accounts for a maximum table name length of 64 characters.
24 * @param string $table_name
25 * The initial table name.
26 * @param string $prefix
27 * (optional) The prefix to use for the new table name. Defaults to 'tmp_'.
30 * The final table name.
32 public static function getTempTableName($table_name, $prefix = 'tmp_') {
33 $tmp_table_name = $prefix . $table_name;
35 // Limit the string to 48 characters, keeping a 16 characters margin for db
37 if (strlen($table_name) > 48) {
38 $short_table_name = substr($table_name, 0, 34);
39 $table_hash = substr(hash('sha256', $table_name), 0, 10);
41 $tmp_table_name = $prefix . $short_table_name . $table_hash;
43 return $tmp_table_name;