diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 7ba31b99c7..ce403352b1 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -94,13 +94,6 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage */ protected $deletedFieldsRepository; - /** - * An array of instantiated table mapping objects, keyed by a unique hash. - * - * @var \Drupal\Core\Entity\Sql\DefaultTableMapping[] - */ - protected $tableMappingCache = []; - /** * Constructs a SqlContentEntityStorageSchema. * @@ -196,19 +189,7 @@ protected function getTableMapping(EntityTypeInterface $entity_type = NULL, arra $field_storage_definitions = $storage_definitions ?: $this->fieldStorageDefinitions; } - // Construct a unique cache key based on the contents of the entity type and - // field storage definitions. - $cache_key_parts[] = spl_object_hash($entity_type); - foreach ($field_storage_definitions as $storage_definition) { - $cache_key_parts[] = spl_object_hash($storage_definition); - } - $cache_key = hash('sha256', implode('', $cache_key_parts)); - - if (!isset($this->tableMappingCache[$cache_key])) { - $this->tableMappingCache[$cache_key] = $this->storage->getCustomTableMapping($entity_type, $field_storage_definitions); - } - - return $this->tableMappingCache[$cache_key]; + return $this->storage->getCustomTableMapping($entity_type, $field_storage_definitions); } /** @@ -271,15 +252,14 @@ protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, E * {@inheritdoc} */ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); - $original_table_mapping = $this->getTableMapping(NULL, [$original]); + $table_mapping = $this->getTableMapping(); if ( $storage_definition->hasCustomStorage() != $original->hasCustomStorage() || $storage_definition->getSchema() != $original->getSchema() || $storage_definition->isRevisionable() != $original->isRevisionable() || - $table_mapping->allowsSharedTableStorage($storage_definition) != $original_table_mapping->allowsSharedTableStorage($original) || - $table_mapping->requiresDedicatedTableStorage($storage_definition) != $original_table_mapping->requiresDedicatedTableStorage($original) + $table_mapping->allowsSharedTableStorage($storage_definition) != $table_mapping->allowsSharedTableStorage($original) || + $table_mapping->requiresDedicatedTableStorage($storage_definition) != $table_mapping->requiresDedicatedTableStorage($original) ) { return TRUE; } diff --git a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install index 402929e6fb..324d4330a0 100644 --- a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install +++ b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install @@ -5,6 +5,8 @@ * Contains install and update hooks. */ +use Drupal\Core\Entity\Sql\SqlContentEntityStorage; + /** * Implements hook_install(). */ @@ -17,7 +19,7 @@ function contact_storage_test_install() { // Update the entity type definition and make it use the default SQL storage. // @see contact_storage_test_entity_type_alter() $entity_type = clone $original; - $entity_type->setStorageClass('\Drupal\Core\Entity\Sql\SqlContentEntityStorage'); + $entity_type->setStorageClass(SqlContentEntityStorage::class); $keys = $entity_type->getKeys(); $keys['id'] = 'id'; $entity_type->set('entity_keys', $keys); diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index 37296dc7df..0ccd6fabc7 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -1205,7 +1205,7 @@ public function testRequiresEntityDataMigration($updated_entity_type_definition, ->method('createHandlerInstance') ->willReturn($original_storage); - $last_installed_schema_repository = $this->getMock(EntityLastInstalledSchemaRepositoryInterface::class); + $last_installed_schema_repository = $this->createMock(EntityLastInstalledSchemaRepositoryInterface::class); $last_installed_schema_repository ->expects($this->any()) ->method('getLastInstalledDefinition') @@ -1392,7 +1392,7 @@ protected function setUpStorageSchema(array $expected = []) { ->will($this->returnValue($this->dbSchemaHandler)); $key_value = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); - $last_installed_schema_repository = $this->getMock(EntityLastInstalledSchemaRepositoryInterface::class); + $last_installed_schema_repository = $this->createMock(EntityLastInstalledSchemaRepositoryInterface::class); $last_installed_schema_repository ->expects($this->any()) ->method('getLastInstalledDefinition') diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 6d0bd7b584..52af4878b0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -137,7 +137,7 @@ protected function setUp() { $this->entityManager->setContainer($this->container); $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class); - $this->entityLastInstalledSchemaRepository = $this->getMock(EntityLastInstalledSchemaRepositoryInterface::class); + $this->entityLastInstalledSchemaRepository = $this->createMock(EntityLastInstalledSchemaRepositoryInterface::class); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');