diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index 4bb30e2..3040bab 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -606,16 +606,16 @@ public function getDedicatedRevisionTableName(FieldStorageDefinitionInterface $s protected function generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, $revision) { $separator = $revision ? '_revision__' : '__'; $table_name = $this->prefix . $storage_definition->getTargetEntityTypeId() . $separator . $storage_definition->getName(); - // Limit the string to 48 characters, keeping a 16 characters margin for db - // prefixes. - if (strlen($table_name) > 48) { + // Limit the string to 48 characters minus the prefix length, keeping a 16 + // characters margin for db prefixes. + if (strlen($table_name) > 48 - strlen($this->prefix)) { // Use a shorter separator, a truncated entity_type, and a hash of the // field storage unique identifier. $separator = $revision ? '_r__' : '__'; // Truncate to the same length for the current and revision tables. $entity_type = substr($storage_definition->getTargetEntityTypeId(), 0, 34); $field_hash = substr(hash('sha256', $storage_definition->getUniqueStorageIdentifier()), 0, 10); - $table_name = $entity_type . $separator . $field_hash; + $table_name = $this->prefix . $entity_type . $separator . $field_hash; } return $table_name; } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index ae41289..966aa00 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -303,7 +303,6 @@ public function setTableMapping(TableMappingInterface $table_mapping) { */ public function setTemporary($temporary) { $this->temporary = $temporary; - $this->initTableLayout(); } /** diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php index d2c0471..58e66a9 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php @@ -158,8 +158,9 @@ public function convertToRevisionable(array &$sandbox, array $fields_to_update = // storage definitions. try { $storage = $this->entityTypeManager->getStorage($this->entityTypeId); + $storage->setEntityType($actual_entity_type); $storage->setTemporary(FALSE); - $actual_table_names = $storage->getTableMapping($sandbox['updated_storage_definitions'], $actual_entity_type)->getTableNames(); + $actual_table_names = $storage->getCustomTableMapping($actual_entity_type, $sandbox['updated_storage_definitions'])->getTableNames(); $table_name_mapping = []; foreach ($actual_table_names as $new_table_name) { @@ -491,7 +492,7 @@ protected function createTemporaryDefinitions(array &$sandbox, array $fields_to_ /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */ $storage = $this->entityTypeManager->getStorage($this->entityTypeId); $storage->setTemporary(TRUE); - $temporary_table_mapping = $storage->getTableMapping($updated_storage_definitions, $temporary_entity_type); + $temporary_table_mapping = $storage->getCustomTableMapping($temporary_entity_type, $updated_storage_definitions); $sandbox['temporary_entity_type'] = $temporary_entity_type; $sandbox['temporary_table_mapping'] = $temporary_table_mapping; @@ -514,9 +515,9 @@ protected function createTemporaryDefinitions(array &$sandbox, array $fields_to_ public static function getPrefixedTableName($table_name, $prefix) { $prefixed_table_name = $prefix . $table_name; - // Limit the string to 48 characters, keeping a 16 characters margin for db - // prefixes. - if (strlen($table_name) > 48) { + // Limit the string to 48 characters minus the length of the prefix, keeping + // a 16 characters margin for db prefixes. + if (strlen($table_name) > 48 - strlen($prefix)) { $short_table_name = substr($table_name, 0, 34); $table_hash = substr(hash('sha256', $table_name), 0, 10); diff --git a/core/modules/system/tests/modules/entity_test_update/src/EntityTestUpdateStorageSchema.php b/core/modules/system/tests/modules/entity_test_update/src/EntityTestUpdateStorageSchema.php index 2b75e83..b1d92d0 100644 --- a/core/modules/system/tests/modules/entity_test_update/src/EntityTestUpdateStorageSchema.php +++ b/core/modules/system/tests/modules/entity_test_update/src/EntityTestUpdateStorageSchema.php @@ -18,7 +18,7 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res $schema = parent::getEntitySchema($entity_type, $reset); if ($entity_type->id() == 'entity_test_update') { - $schema[$entity_type->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []); + $schema[$this->storage->getTableMapping()->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []); } return $schema; }