diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index d6ca5db..96142e9 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -169,6 +169,7 @@ public static function create(ContentEntityTypeInterface $entity_type, array $st $all_fields = array_merge($key_fields, array_diff($all_fields, $key_fields)); $revision_metadata_fields = $revisionable ? array_values($entity_type->getRevisionMetadataKeys()) : []; + $revision_metadata_fields = array_intersect($revision_metadata_fields, array_keys($storage_definitions)); if (!$revisionable && !$translatable) { // The base layout stores all the base field values in the base table. diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index c73a28c..37f3fb6 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -3,7 +3,6 @@ namespace Drupal\Core\Entity\Sql; use Drupal\Core\Database\Connection; -use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityManagerInterface; @@ -51,14 +50,6 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage protected $fieldStorageDefinitions; /** - * The original storage field definitions for this entity type. Used during - * field schema updates. - * - * @var \Drupal\Core\Field\FieldDefinitionInterface[] - */ - protected $originalDefinitions; - - /** * The storage object for the given entity type. * * @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage @@ -94,6 +85,13 @@ 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. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -107,8 +105,8 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage */ public function __construct(EntityManagerInterface $entity_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database) { $this->entityManager = $entity_manager; - $this->entityType = $entity_type; - $this->fieldStorageDefinitions = $entity_manager->getFieldStorageDefinitions($entity_type->id()); + $this->entityType = $this->entityManager->getLastInstalledDefinition($entity_type->id()); + $this->fieldStorageDefinitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type->id()); $this->storage = $storage; $this->database = $database; } @@ -147,6 +145,46 @@ protected function deletedFieldsRepository() { } /** + * Refreshes the table mapping with updated definitions. + * + * @param \Drupal\Core\Entity\EntityTypeInterface|null $entity_type + * (optional) An entity type definition. Defaults to the last installed + * entity type definition. + * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[]|null $storage_definitions + * (optional) An array of field storage definitions. Defaults to the last + * installed field storage definition. + * + * @return \Drupal\Core\Entity\Sql\DefaultTableMapping + * A table mapping object. + */ + protected function getTableMapping(EntityTypeInterface $entity_type = NULL, array $storage_definitions = NULL) { + $entity_type = $entity_type ?: $this->entityType; + + // Allow passing a single field storage definition when updating a field. + if ($storage_definitions && count($storage_definitions) === 1) { + $storage_definition = reset($storage_definitions); + $field_storage_definitions = [$storage_definition->getName() => $storage_definition] + $this->fieldStorageDefinitions; + } + else { + $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]; + } + + /** * {@inheritdoc} */ public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { @@ -206,14 +244,15 @@ protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, E * {@inheritdoc} */ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $original_table_mapping = $this->getTableMapping(NULL, [$original]); if ( $storage_definition->hasCustomStorage() != $original->hasCustomStorage() || $storage_definition->getSchema() != $original->getSchema() || $storage_definition->isRevisionable() != $original->isRevisionable() || - $table_mapping->allowsSharedTableStorage($storage_definition) != $table_mapping->allowsSharedTableStorage($original) || - $table_mapping->requiresDedicatedTableStorage($storage_definition) != $table_mapping->requiresDedicatedTableStorage($original) + $table_mapping->allowsSharedTableStorage($storage_definition) != $original_table_mapping->allowsSharedTableStorage($original) || + $table_mapping->requiresDedicatedTableStorage($storage_definition) != $original_table_mapping->requiresDedicatedTableStorage($original) ) { return TRUE; } @@ -246,7 +285,7 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac */ protected function getSchemaFromStorageDefinition(FieldStorageDefinitionInterface $storage_definition) { assert(!$storage_definition->hasCustomStorage()); - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $schema = []; if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { $schema = $this->getDedicatedTableSchema($storage_definition); @@ -303,6 +342,12 @@ public function requiresFieldDataMigration(FieldStorageDefinitionInterface $stor */ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { $this->checkEntityType($entity_type); + + // When installing an entity type, we have to use the live (in-code) entity + // type and field storage definitions. + $this->entityType = $entity_type; + $this->fieldStorageDefinitions = $this->entityManager->getFieldStorageDefinitions($entity_type->id()); + $schema_handler = $this->database->schema(); // Create entity tables. @@ -314,7 +359,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { } // Create dedicated field tables. - $table_mapping = $this->storage->getTableMapping($this->fieldStorageDefinitions); + $table_mapping = $this->getTableMapping(); foreach ($this->fieldStorageDefinitions as $field_storage_definition) { if ($table_mapping->requiresDedicatedTableStorage($field_storage_definition)) { $this->createDedicatedTableSchema($field_storage_definition); @@ -337,6 +382,8 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI $this->checkEntityType($entity_type); $this->checkEntityType($original); + $this->entityType = $entity_type; + // If no schema changes are needed, we don't need to do anything. if (!$this->requiresEntityStorageSchemaChanges($entity_type, $original)) { return; @@ -347,39 +394,15 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI throw new EntityStorageException('The SQL storage cannot change the schema for an existing entity type (' . $entity_type->id() . ') with data.'); } - // If we have no data just recreate the entity schema from scratch. - if ($this->isTableEmpty($this->storage->getBaseTable())) { - if ($this->database->supportsTransactionalDDL()) { - // If the database supports transactional DDL, we can go ahead and rely - // on it. If not, we will have to rollback manually if something fails. - $transaction = $this->database->startTransaction(); - } - try { - $this->onEntityTypeDelete($original); - $this->onEntityTypeCreate($entity_type); - } - catch (\Exception $e) { - if ($this->database->supportsTransactionalDDL()) { - $transaction->rollBack(); - } - else { - // Recreate original schema. - $this->onEntityTypeCreate($original); - } - throw $e; - } - } - else { - // Drop original indexes and unique keys. - $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($entity_type)); + // Drop original indexes and unique keys. + $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($entity_type)); - // Create new indexes and unique keys. - $entity_schema = $this->getEntitySchema($entity_type, TRUE); - $this->createEntitySchemaIndexes($entity_schema); + // Create new indexes and unique keys. + $entity_schema = $this->getEntitySchema($entity_type, TRUE); + $this->createEntitySchemaIndexes($entity_schema); - // Store the updated entity schema. - $this->saveEntitySchemaData($entity_type, $entity_schema); - } + // Store the updated entity schema. + $this->saveEntitySchemaData($entity_type, $entity_schema); } /** @@ -389,18 +412,15 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) { $this->checkEntityType($entity_type); $schema_handler = $this->database->schema(); - $field_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type->id()); - $table_mapping = $this->storage->getCustomTableMapping($entity_type, $field_storage_definitions); - // Delete entity and field tables. - foreach ($table_mapping->getTableNames() as $table_name) { + foreach ($this->getTableMapping($entity_type)->getTableNames() as $table_name) { if ($schema_handler->tableExists($table_name)) { $schema_handler->dropTable($table_name); } } // Delete the field schema data. - foreach ($field_storage_definitions as $field_storage_definition) { + foreach ($this->fieldStorageDefinitions as $field_storage_definition) { $this->deleteFieldSchemaData($field_storage_definition); } @@ -412,6 +432,16 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) { * {@inheritdoc} */ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) { + // During a schema conversion for an entity type from non-revisionable to + // revisionable, the schema for all the field storage definitions is already + // in place, so there is nothing to do here. + // @todo Remove in https://www.drupal.org/node/2984782. + if (isset($storage_definition->_skip_schema_operation)) { + unset($storage_definition->_skip_schema_operation); + return; + } + + $this->fieldStorageDefinitions[$storage_definition->getName()] = $storage_definition; $this->performFieldSchemaOperation('create', $storage_definition); } @@ -419,8 +449,15 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $ * {@inheritdoc} */ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - // Store original definitions so that switching between shared and dedicated - // field table layout works. + // During a schema conversion for an entity type from non-revisionable to + // revisionable, the schema for all the field storage definitions is already + // in place, so there is nothing to do here. + // @todo Remove in https://www.drupal.org/node/2984782. + if (isset($storage_definition->_skip_schema_operation)) { + unset($storage_definition->_skip_schema_operation); + return; + } + $this->performFieldSchemaOperation('update', $storage_definition, $original); } @@ -428,20 +465,9 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $ * {@inheritdoc} */ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) { - try { - $has_data = $this->storage->countFieldData($storage_definition, TRUE); - } - catch (DatabaseExceptionWrapper $e) { - // This may happen when changing field storage schema, since we are not - // able to use a table mapping matching the passed storage definition. - // @todo Revisit this once we are able to instantiate the table mapping - // properly. See https://www.drupal.org/node/2274017. - return; - } - // If the field storage does not have any data, we can safely delete its // schema. - if (!$has_data) { + if (!$this->storage->countFieldData($storage_definition, TRUE)) { $this->performFieldSchemaOperation('delete', $storage_definition); return; } @@ -451,9 +477,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ return; } - // Retrieve a table mapping which contains the deleted field still. - $storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id()); - $table_mapping = $this->storage->getTableMapping($storage_definitions); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $field_table_name = $table_mapping->getFieldTableName($storage_definition->getName()); if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { @@ -475,8 +499,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ // Refresh the table mapping to use the deleted storage definition. $deleted_storage_definition = $this->deletedFieldsRepository()->getFieldStorageDefinitions()[$storage_definition->getUniqueStorageIdentifier()]; - $original_storage_definitions = [$storage_definition->getName() => $deleted_storage_definition] + $storage_definitions; - $table_mapping = $this->storage->getTableMapping($original_storage_definitions); + $table_mapping = $this->getTableMapping(NULL, [$deleted_storage_definition]); $dedicated_table_field_schema = $this->getDedicatedTableSchema($deleted_storage_definition); $dedicated_table_field_columns = $table_mapping->getColumnNames($deleted_storage_definition->getName()); @@ -681,7 +704,7 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res } // We need to act only on shared entity schema tables. - $table_mapping = $this->storage->getCustomTableMapping($entity_type, $this->fieldStorageDefinitions); + $table_mapping = $this->getTableMapping($entity_type); $table_names = array_diff($table_mapping->getTableNames(), $table_mapping->getDedicatedTableNames()); foreach ($table_names as $table_name) { if (!isset($schema[$table_name])) { @@ -715,7 +738,9 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res // Add an index for the 'published' entity key. if (is_subclass_of($entity_type->getClass(), EntityPublishedInterface::class)) { $published_key = $entity_type->getKey('published'); - if ($published_key && !$this->fieldStorageDefinitions[$published_key]->hasCustomStorage()) { + if ($published_key + && isset($this->fieldStorageDefinitions[$published_key]) + && !$this->fieldStorageDefinitions[$published_key]->hasCustomStorage()) { $published_field_table = $table_mapping->getFieldTableName($published_key); $id_key = $entity_type->getKey('id'); if ($bundle_key = $entity_type->getKey('bundle')) { @@ -770,7 +795,7 @@ protected function getEntitySchemaData(ContentEntityTypeInterface $entity_type, // Collect all possible field schema identifiers for shared table fields. // These will be used to detect entity schema data in the subsequent loop. $field_schema_identifiers = []; - $table_mapping = $this->storage->getTableMapping($this->fieldStorageDefinitions); + $table_mapping = $this->getTableMapping($entity_type); foreach ($this->fieldStorageDefinitions as $field_name => $storage_definition) { if ($table_mapping->allowsSharedTableStorage($storage_definition)) { // Make sure both base identifier names and suffixed names are listed. @@ -1279,7 +1304,7 @@ protected function processFieldStorageSchema(array &$field_storage_schema) { * required) only for updates. Defaults to NULL. */ protected function performFieldSchemaOperation($operation, FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original = NULL) { - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { $this->{$operation . 'DedicatedTableSchema'}($storage_definition, $original); } @@ -1319,7 +1344,7 @@ protected function createDedicatedTableSchema(FieldStorageDefinitionInterface $s */ protected function createSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, $only_save = FALSE) { $created_field_name = $storage_definition->getName(); - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $column_names = $table_mapping->getColumnNames($created_field_name); $schema_handler = $this->database->schema(); $shared_table_names = array_diff($table_mapping->getTableNames(), $table_mapping->getDedicatedTableNames()); @@ -1364,7 +1389,11 @@ protected function createSharedTableSchema(FieldStorageDefinitionInterface $stor if (!$only_save) { // Make sure any entity index involving this field is re-created if // needed. - $this->createEntitySchemaIndexes($this->getEntitySchema($this->entityType), $storage_definition); + $entity_schema = $this->getEntitySchema($this->entityType); + $this->createEntitySchemaIndexes($entity_schema, $storage_definition); + + // Store the updated entity schema. + $this->saveEntitySchemaData($this->entityType, $entity_schema); } } @@ -1375,7 +1404,7 @@ protected function createSharedTableSchema(FieldStorageDefinitionInterface $stor * The storage definition of the field being deleted. */ protected function deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition) { - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $table_name = $table_mapping->getDedicatedDataTableName($storage_definition, $storage_definition->isDeleted()); if ($this->database->schema()->tableExists($table_name)) { $this->database->schema()->dropTable($table_name); @@ -1400,9 +1429,7 @@ protected function deleteSharedTableSchema(FieldStorageDefinitionInterface $stor $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($this->entityType), $storage_definition); $deleted_field_name = $storage_definition->getName(); - $table_mapping = $this->storage->getTableMapping( - $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id()) - ); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $column_names = $table_mapping->getColumnNames($deleted_field_name); $schema_handler = $this->database->schema(); $shared_table_names = array_diff($table_mapping->getTableNames(), $table_mapping->getDedicatedTableNames()); @@ -1483,7 +1510,7 @@ protected function updateDedicatedTableSchema(FieldStorageDefinitionInterface $s // There is data, so there are no column changes. Drop all the prior // indexes and create all the new ones, except for all the priors that // exist unchanged. - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $table = $table_mapping->getDedicatedDataTableName($original); $revision_table = $table_mapping->getDedicatedRevisionTableName($original); @@ -1573,7 +1600,7 @@ protected function updateSharedTableSchema(FieldStorageDefinitionInterface $stor } $updated_field_name = $storage_definition->getName(); - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $column_names = $table_mapping->getColumnNames($updated_field_name); $schema_handler = $this->database->schema(); @@ -1648,7 +1675,7 @@ protected function createEntitySchemaIndexes(array $entity_schema, FieldStorageD $schema_handler = $this->database->schema(); if ($storage_definition) { - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $column_names = $table_mapping->getColumnNames($storage_definition->getName()); } @@ -1707,7 +1734,7 @@ protected function deleteEntitySchemaIndexes(array $entity_schema_data, FieldSto $schema_handler = $this->database->schema(); if ($storage_definition) { - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $column_names = $table_mapping->getColumnNames($storage_definition->getName()); } @@ -1781,7 +1808,7 @@ protected function hasNullFieldPropertyData($table_name, $column_name) { */ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) { $schema = []; - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); $field_schema = $storage_definition->getSchema(); // Check that the schema does not include forbidden column names. @@ -1805,20 +1832,16 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st } if ($initial_value_field_name = $storage_definition->getInitialValueFromField()) { - // Check that the field used for populating initial values is valid. We - // must use the last installed version of that, as the new field might - // be created in an update function and the storage definition of the - // "from" field might get changed later. - $last_installed_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id()); - if (!isset($last_installed_storage_definitions[$initial_value_field_name])) { + // Check that the field used for populating initial values is valid. + if (!isset($this->fieldStorageDefinitions[$initial_value_field_name])) { throw new FieldException("Illegal initial value definition on {$storage_definition->getName()}: The field $initial_value_field_name does not exist."); } - if ($storage_definition->getType() !== $last_installed_storage_definitions[$initial_value_field_name]->getType()) { + if ($storage_definition->getType() !== $this->fieldStorageDefinitions[$initial_value_field_name]->getType()) { throw new FieldException("Illegal initial value definition on {$storage_definition->getName()}: The field types do not match."); } - if (!$table_mapping->allowsSharedTableStorage($last_installed_storage_definitions[$initial_value_field_name])) { + if (!$table_mapping->allowsSharedTableStorage($this->fieldStorageDefinitions[$initial_value_field_name])) { throw new FieldException("Illegal initial value definition on {$storage_definition->getName()}: Both fields have to be stored in the shared entity tables."); } @@ -2046,7 +2069,7 @@ protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $stor // Check that the schema does not include forbidden column names. $schema = $storage_definition->getSchema(); $properties = $storage_definition->getPropertyDefinitions(); - $table_mapping = $this->storage->getTableMapping(); + $table_mapping = $this->getTableMapping($entity_type, [$storage_definition]); if (array_intersect(array_keys($schema['columns']), $table_mapping->getReservedColumns())) { throw new FieldException("Illegal field column names on {$storage_definition->getName()}"); } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php index aa92e0f..b879cae 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchemaConverter.php @@ -191,13 +191,13 @@ public function convertToRevisionable(array &$sandbox, array $fields_to_update = $this->installedStorageSchema->set($this->entityTypeId . '.field_schema_data.' . $storage_definition->getName(), $field_schema_data); } + // Update the field storage definitions. + $this->updateFieldStorageDefinitionsToRevisionable($actual_entity_type, $sandbox['original_storage_definitions'], $fields_to_update); + // Instruct the entity schema handler that data migration has been // handled already and update the entity type. $actual_entity_type->set('requires_data_migration', FALSE); $this->entityDefinitionUpdateManager->updateEntityType($actual_entity_type); - - // Update the field storage definitions. - $this->updateFieldStorageDefinitionsToRevisionable($actual_entity_type, $sandbox['original_storage_definitions'], $fields_to_update); } catch (\Exception $e) { // Something went wrong, bring back the original tables. @@ -368,6 +368,7 @@ protected function updateFieldStorageDefinitionsToRevisionable(ContentEntityType $updated_storage_definitions[$field_name]->setRevisionable(TRUE); if ($update_cached_definitions) { + $updated_storage_definitions[$field_name]->_skip_schema_operation = TRUE; $this->entityDefinitionUpdateManager->updateFieldStorageDefinition($updated_storage_definitions[$field_name]); } } @@ -383,6 +384,7 @@ protected function updateFieldStorageDefinitionsToRevisionable(ContentEntityType ->setSetting('unsigned', TRUE); if ($update_cached_definitions) { + $revision_field->_skip_schema_operation = TRUE; $this->entityDefinitionUpdateManager->installFieldStorageDefinition($revision_field->getName(), $entity_type->id(), $entity_type->getProvider(), $revision_field); } $updated_storage_definitions[$entity_type->getKey('revision')] = $revision_field; @@ -400,6 +402,7 @@ protected function updateFieldStorageDefinitionsToRevisionable(ContentEntityType ->setRevisionable(TRUE); if ($update_cached_definitions) { + $storage_definition->_skip_schema_operation = TRUE; $this->entityDefinitionUpdateManager->installFieldStorageDefinition($field_name, $entity_type->id(), $entity_type->getProvider(), $storage_definition); } $updated_storage_definitions[$field_name] = $storage_definition; @@ -417,6 +420,7 @@ protected function updateFieldStorageDefinitionsToRevisionable(ContentEntityType ->setTranslatable(TRUE); if ($update_cached_definitions) { + $revision_translation_affected_field->_skip_schema_operation = TRUE; $this->entityDefinitionUpdateManager->installFieldStorageDefinition($revision_translation_affected_field->getName(), $entity_type->id(), $entity_type->getProvider(), $revision_translation_affected_field); } $updated_storage_definitions[$entity_type->getKey('revision_translation_affected')] = $revision_translation_affected_field; diff --git a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php index e67629b..6ef363c 100644 --- a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php +++ b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php @@ -7,7 +7,6 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\FieldableEntityStorageInterface; -use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -82,16 +81,7 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $ // @todo Forward this to all interested handlers, not only storage, once // iterating handlers is possible: https://www.drupal.org/node/2332857. - $storage = clone $this->entityTypeManager->getStorage($entity_type_id); - - // Entity type definition updates can change the schema by adding or - // removing entity tables (for example when switching an entity type from - // non-revisionable to revisionable), so CRUD operations on a field storage - // definition need to use the last installed entity type schema. - if ($storage instanceof SqlContentEntityStorage - && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) { - $storage->setEntityType($last_installed_entity_type); - } + $storage = $this->entityTypeManager->getStorage($entity_type_id); if ($storage instanceof FieldStorageDefinitionListenerInterface) { $storage->onFieldStorageDefinitionCreate($storage_definition); @@ -111,16 +101,7 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $ // @todo Forward this to all interested handlers, not only storage, once // iterating handlers is possible: https://www.drupal.org/node/2332857. - $storage = clone $this->entityTypeManager->getStorage($entity_type_id); - - // Entity type definition updates can change the schema by adding or - // removing entity tables (for example when switching an entity type from - // non-revisionable to revisionable), so CRUD operations on a field storage - // definition need to use the last installed entity type schema. - if ($storage instanceof SqlContentEntityStorage - && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) { - $storage->setEntityType($last_installed_entity_type); - } + $storage = $this->entityTypeManager->getStorage($entity_type_id); if ($storage instanceof FieldStorageDefinitionListenerInterface) { $storage->onFieldStorageDefinitionUpdate($storage_definition, $original); @@ -140,16 +121,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ // @todo Forward this to all interested handlers, not only storage, once // iterating handlers is possible: https://www.drupal.org/node/2332857. - $storage = clone $this->entityTypeManager->getStorage($entity_type_id); - - // Entity type definition updates can change the schema by adding or - // removing entity tables (for example when switching an entity type from - // non-revisionable to revisionable), so CRUD operations on a field storage - // definition need to use the last installed entity type schema. - if ($storage instanceof SqlContentEntityStorage - && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) { - $storage->setEntityType($last_installed_entity_type); - } + $storage = $this->entityTypeManager->getStorage($entity_type_id); // Keep the field definition in the deleted fields repository so we can use // it later during field_purge_batch(), but only if the field has data. diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php index 4078782..db255d7 100644 --- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php +++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php @@ -35,9 +35,9 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal6TestBase { */ protected function setUp() { parent::setUp(); + $this->installEntitySchema('block_content'); $this->installConfig(['block']); $this->installConfig(['block_content']); - $this->installEntitySchema('block_content'); $this->executeMigrations([ 'd6_filter_format', diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php index e0876fd..acdc5c5 100644 --- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php +++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php @@ -38,8 +38,8 @@ protected function setUp() { // Install the themes used for this test. $this->container->get('theme_installer')->install(['bartik', 'test_theme']); - $this->installConfig(['block_content']); $this->installEntitySchema('block_content'); + $this->installConfig(['block_content']); // Set Bartik as the default public theme. $config = $this->config('system.theme'); diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php index 6f07dc9..c16214b 100644 --- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php +++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php @@ -37,8 +37,8 @@ protected function setUp() { // Install the themes used for this test. $this->container->get('theme_installer')->install(['bartik', 'seven']); - $this->installConfig(static::$modules); $this->installEntitySchema('block_content'); + $this->installConfig(static::$modules); // Set Bartik and Seven as the default public and admin theme. $config = $this->config('system.theme'); diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentBodyFieldTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentBodyFieldTest.php index 7d34373..8eb60a6 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentBodyFieldTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentBodyFieldTest.php @@ -22,8 +22,8 @@ class MigrateBlockContentBodyFieldTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(['block_content']); $this->installEntitySchema('block_content'); + $this->installConfig(['block_content']); $this->executeMigrations([ 'block_content_type', 'block_content_body_field', diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityDisplayTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityDisplayTest.php index 5eb9e41..5a05637 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityDisplayTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityDisplayTest.php @@ -22,6 +22,7 @@ class MigrateBlockContentEntityDisplayTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); + $this->installEntitySchema('block_content'); $this->installConfig(static::$modules); $this->executeMigrations([ 'block_content_type', diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityFormDisplayTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityFormDisplayTest.php index 8fed905..645f70b 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityFormDisplayTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentEntityFormDisplayTest.php @@ -22,6 +22,7 @@ class MigrateBlockContentEntityFormDisplayTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); + $this->installEntitySchema('block_content'); $this->installConfig(static::$modules); $this->executeMigrations([ 'block_content_type', diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentTypeTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentTypeTest.php index 4accc20..046284d 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentTypeTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentTypeTest.php @@ -20,8 +20,8 @@ class MigrateBlockContentTypeTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(['block_content']); $this->installEntitySchema('block_content'); + $this->installConfig(['block_content']); $this->executeMigration('block_content_type'); } diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php index 87e6fac..40c30a6 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php @@ -22,8 +22,8 @@ class MigrateBlockContentTest extends MigrateDrupal6TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(['block_content']); $this->installEntitySchema('block_content'); + $this->installConfig(['block_content']); $this->executeMigrations([ 'd6_filter_format', diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php index 2847e35..99bbc42 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateCustomBlockContentTranslationTest.php @@ -28,8 +28,8 @@ class MigrateCustomBlockContentTranslationTest extends MigrateDrupal6TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(['block_content']); $this->installEntitySchema('block_content'); + $this->installConfig(['block_content']); $this->executeMigrations([ 'language', 'd6_filter_format', diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d7/MigrateCustomBlockTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d7/MigrateCustomBlockTest.php index 706a7cc..9147b38 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d7/MigrateCustomBlockTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d7/MigrateCustomBlockTest.php @@ -24,8 +24,8 @@ class MigrateCustomBlockTest extends MigrateDrupal7TestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(static::$modules); $this->installEntitySchema('block_content'); + $this->installConfig(static::$modules); $this->executeMigrations([ 'd7_filter_format', diff --git a/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php b/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php index cab65e3..c5baf6d 100644 --- a/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php +++ b/core/modules/book/tests/src/Kernel/Migrate/d6/MigrateBookTest.php @@ -15,7 +15,7 @@ class MigrateBookTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['book', 'menu_ui']; + public static $modules = ['book', 'node', 'menu_ui']; /** * {@inheritdoc} diff --git a/core/modules/comment/tests/src/Kernel/CommentItemTest.php b/core/modules/comment/tests/src/Kernel/CommentItemTest.php index 85f6112..c172caf 100644 --- a/core/modules/comment/tests/src/Kernel/CommentItemTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentItemTest.php @@ -27,6 +27,7 @@ class CommentItemTest extends FieldKernelTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('comment'); $this->installSchema('comment', ['comment_entity_statistics']); $this->installConfig(['comment']); } diff --git a/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php b/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php index adbe1b0..6d72cfe 100644 --- a/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php @@ -30,6 +30,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('comment'); + $this->installEntitySchema('entity_test_string_id'); $this->installSchema('comment', ['comment_entity_statistics']); // Create the comment body field storage. $this->installConfig(['field']); 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 c56d5b5..970b69b 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 @@ -9,15 +9,19 @@ * Implements hook_install(). */ function contact_storage_test_install() { - $entity_manager = \Drupal::entityManager(); - $entity_type = $entity_manager->getDefinition('contact_message'); + $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager(); - // Recreate the original entity type definition, in order to notify the - // manager of what changed. The change of storage backend will trigger - // schema installation. - // @see contact_storage_test_entity_type_alter() - $original = clone $entity_type; - $original->setStorageClass('Drupal\Core\Entity\ContentEntityNullStorage'); + $original = $entity_definition_update_manager->getEntityType('contact_message'); + $entity_definition_update_manager->uninstallEntityType($original); + + $entity_type = clone $original; - $entity_manager->onEntityTypeUpdate($entity_type, $original); + // Update the entity type definition and make it use the default SQL storage. + // @see contact_storage_test_entity_type_alter() + $entity_type->setStorageClass('\Drupal\Core\Entity\Sql\SqlContentEntityStorage'); + $keys = $entity_type->getKeys(); + $keys['id'] = 'id'; + $entity_type->set('entity_keys', $keys); + $entity_type->set('base_table', 'contact_message'); + $entity_definition_update_manager->installEntityType($entity_type); } diff --git a/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_autocreate_2412569.yml b/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_autocreate_2412569.yml index 19e4a6a..1e474e8 100644 --- a/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_autocreate_2412569.yml +++ b/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_autocreate_2412569.yml @@ -17,4 +17,4 @@ cardinality: 1 translatable: true indexes: { } persist_with_no_fields: false -custom_storage: false +custom_storage: true diff --git a/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_views_select_2429191.yml b/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_views_select_2429191.yml index 84d8eca..950d3e0 100644 --- a/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_views_select_2429191.yml +++ b/core/modules/field/tests/fixtures/update/field.storage.node.field_ref_views_select_2429191.yml @@ -17,3 +17,4 @@ cardinality: 1 translatable: true indexes: { } persist_with_no_fields: false +custom_storage: true diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index ee831ff..f62b325 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -21,13 +21,13 @@ function field_test_entity_type_alter(array &$entity_types) { function field_test_entity_info_translatable($entity_type_id = NULL, $translatable = NULL) { $stored_value = &drupal_static(__FUNCTION__, []); if (isset($entity_type_id)) { - $entity_manager = \Drupal::entityManager(); - $original = $entity_manager->getDefinition($entity_type_id); + $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager(); + $entity_type = $entity_definition_update_manager->getEntityType($entity_type_id); $stored_value[$entity_type_id] = $translatable; - if ($translatable != $original->isTranslatable()) { - $entity_manager->clearCachedDefinitions(); - $entity_type = $entity_manager->getDefinition($entity_type_id); - $entity_manager->onEntityTypeUpdate($entity_type, $original); + if ($translatable != $entity_type->isTranslatable()) { + $entity_definition_update_manager->uninstallEntityType($entity_type); + $entity_type->set('translatable', $translatable); + $entity_definition_update_manager->installEntityType($entity_type); } } return $stored_value; diff --git a/core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php b/core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php index a2a2c21..988998f 100644 --- a/core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php +++ b/core/modules/field/tests/src/Kernel/ConfigFieldDefinitionTest.php @@ -43,6 +43,7 @@ protected function setUp() { $this->entityManager = $this->container->get('entity.manager'); // Create a second field on 'entity_test_rev'. + $this->installEntitySchema('entity_test_rev'); $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev'); } diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php index 7347c04..220be8c 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php @@ -15,7 +15,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['menu_ui']; + public static $modules = ['menu_ui', 'node']; /** * {@inheritdoc} diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php index 6c4e29c..6914d0d 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php @@ -17,7 +17,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase { /** * {@inheritdoc} */ - public static $modules = ['menu_ui']; + public static $modules = ['menu_ui', 'node']; /** * Tests migration of file variables to file.settings.yml. diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php index 0a7e9dc..518720c 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php @@ -13,7 +13,7 @@ */ class MigrateViewModesTest extends MigrateDrupal7TestBase { - public static $modules = ['comment', 'node', 'taxonomy']; + public static $modules = ['comment', 'node', 'taxonomy', 'text']; /** * {@inheritdoc} diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php index b069387..8c45479 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php @@ -13,6 +13,11 @@ class RollbackViewModesTest extends MigrateViewModesTest { /** + * {@inheritdoc} + */ + public static $modules = ['text']; + + /** * Tests migrating D7 view modes, then rolling back. */ public function testMigration() { diff --git a/core/modules/field/tests/src/Kernel/TranslationTest.php b/core/modules/field/tests/src/Kernel/TranslationTest.php index 5d03f69..1a101b7 100644 --- a/core/modules/field/tests/src/Kernel/TranslationTest.php +++ b/core/modules/field/tests/src/Kernel/TranslationTest.php @@ -72,6 +72,7 @@ class TranslationTest extends FieldKernelTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('node'); $this->installConfig(['language']); $this->fieldName = mb_strtolower($this->randomMachineName()); diff --git a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php index 5ee2d40..5f0b5f1 100644 --- a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php +++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php @@ -32,6 +32,7 @@ class EntityDisplayTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('entity_test'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installConfig(['field', 'node', 'user']); diff --git a/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php index c1d22b7..2baee4d 100644 --- a/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php +++ b/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php @@ -24,6 +24,7 @@ class EntityFormDisplayTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('entity_test'); } /** diff --git a/core/modules/file/tests/fixtures/update/field.storage.node.field_file_generic_2677990.yml b/core/modules/file/tests/fixtures/update/field.storage.node.field_file_generic_2677990.yml index 2c4a297..0eda228 100644 --- a/core/modules/file/tests/fixtures/update/field.storage.node.field_file_generic_2677990.yml +++ b/core/modules/file/tests/fixtures/update/field.storage.node.field_file_generic_2677990.yml @@ -20,4 +20,4 @@ cardinality: 1 translatable: true indexes: { } persist_with_no_fields: false -custom_storage: false +custom_storage: true diff --git a/core/modules/file/tests/fixtures/update/field.storage.node.field_file_table_2677990.yml b/core/modules/file/tests/fixtures/update/field.storage.node.field_file_table_2677990.yml index bf93af8..8d75eb7 100644 --- a/core/modules/file/tests/fixtures/update/field.storage.node.field_file_table_2677990.yml +++ b/core/modules/file/tests/fixtures/update/field.storage.node.field_file_table_2677990.yml @@ -20,4 +20,4 @@ cardinality: 1 translatable: true indexes: { } persist_with_no_fields: false -custom_storage: false +custom_storage: true diff --git a/core/modules/file/tests/src/Kernel/FileItemValidationTest.php b/core/modules/file/tests/src/Kernel/FileItemValidationTest.php index ba763b6..6fbc82f 100644 --- a/core/modules/file/tests/src/Kernel/FileItemValidationTest.php +++ b/core/modules/file/tests/src/Kernel/FileItemValidationTest.php @@ -35,6 +35,7 @@ class FileItemValidationTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installEntitySchema('entity_test'); $this->installEntitySchema('user'); $this->installEntitySchema('file'); $this->installSchema('file', 'file_usage'); diff --git a/core/modules/image/tests/src/Kernel/ImageStyleIntegrationTest.php b/core/modules/image/tests/src/Kernel/ImageStyleIntegrationTest.php index e471c99..43d714c 100644 --- a/core/modules/image/tests/src/Kernel/ImageStyleIntegrationTest.php +++ b/core/modules/image/tests/src/Kernel/ImageStyleIntegrationTest.php @@ -23,6 +23,14 @@ class ImageStyleIntegrationTest extends KernelTestBase { public static $modules = ['image', 'file', 'field', 'system', 'user', 'node']; /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('node'); + } + + /** * Tests the dependency between ImageStyle and entity display components. */ public function testEntityDisplayDependency() { diff --git a/core/modules/image/tests/src/Kernel/Views/ImageViewsDataTest.php b/core/modules/image/tests/src/Kernel/Views/ImageViewsDataTest.php index a324d5e..b7fe074 100644 --- a/core/modules/image/tests/src/Kernel/Views/ImageViewsDataTest.php +++ b/core/modules/image/tests/src/Kernel/Views/ImageViewsDataTest.php @@ -22,6 +22,15 @@ class ImageViewsDataTest extends ViewsKernelTestBase { public static $modules = ['image', 'file', 'views', 'entity_test', 'user', 'field']; /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_mul'); + } + + /** * Tests views data generated for image field relationship. * * @see image_field_views_data() diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php index d15446f..e2b6052 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/EntityRevisionTest.php @@ -35,10 +35,10 @@ class EntityRevisionTest extends MigrateTestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig('node'); - $this->installSchema('node', ['node_access']); $this->installEntitySchema('node'); $this->installEntitySchema('user'); + $this->installConfig('node'); + $this->installSchema('node', ['node_access']); } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php index 3a9467e..b4707dc 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php @@ -29,6 +29,17 @@ protected function setUp() { parent::setUp(); $this->loadFixture($this->getFixtureFilePath()); + + $this->installEntitySchema('node'); + if (in_array('comment', static::$modules, TRUE)) { + $this->installEntitySchema('comment'); + } + if (in_array('taxonomy', static::$modules, TRUE)) { + $this->installEntitySchema('taxonomy_term'); + } + if (in_array('user', static::$modules, TRUE)) { + $this->installEntitySchema('user'); + } } /** diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php index 3afa82d..3236db5 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php @@ -15,6 +15,19 @@ protected function setUp() { parent::setUp(); $this->loadFixture($this->getFixtureFilePath()); + + if (in_array('comment', static::$modules, TRUE)) { + $this->installEntitySchema('comment'); + } + if (in_array('node', static::$modules, TRUE)) { + $this->installEntitySchema('node'); + } + if (in_array('taxonomy', static::$modules, TRUE)) { + $this->installEntitySchema('taxonomy_term'); + } + if (in_array('user', static::$modules, TRUE)) { + $this->installEntitySchema('user'); + } } /** diff --git a/core/modules/options/tests/src/Kernel/Views/FileViewsDataTest.php b/core/modules/options/tests/src/Kernel/Views/FileViewsDataTest.php index c5f2902..416af44 100644 --- a/core/modules/options/tests/src/Kernel/Views/FileViewsDataTest.php +++ b/core/modules/options/tests/src/Kernel/Views/FileViewsDataTest.php @@ -22,6 +22,15 @@ class FileViewsDataTest extends ViewsKernelTestBase { public static $modules = ['file', 'views', 'entity_test', 'user', 'field']; /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_mul'); + } + + /** * Tests views data generated for file field relationship. * * @see file_field_views_data() diff --git a/core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php b/core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php index d023598..31554f8 100644 --- a/core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php +++ b/core/modules/options/tests/src/Kernel/Views/ViewsDataTest.php @@ -30,6 +30,7 @@ class ViewsDataTest extends OptionsTestBase { protected function setUp($import_test_views = TRUE) { parent::setUp(); + $this->installEntitySchema('entity_test'); $field_name = 'test_options'; $this->fieldStorage = FieldStorageConfig::create([ 'field_name' => $field_name, diff --git a/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php b/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php index d481291..f935a4e 100644 --- a/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php +++ b/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php @@ -18,7 +18,15 @@ class ResponsiveImageIntegrationTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['responsive_image', 'field', 'image', 'file', 'entity_test', 'breakpoint', 'responsive_image_test_module']; + public static $modules = ['responsive_image', 'field', 'image', 'file', 'entity_test', 'breakpoint', 'responsive_image_test_module', 'user']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('entity_test'); + } /** * Tests integration with entity view display. diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index fc0d918..2be141b 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -270,6 +270,7 @@ public function testEnableModulesFixedList() { $this->enableModules(['field_test']); // Create a field. + $this->installEntitySchema('entity_test'); $display = EntityViewDisplay::create([ 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', diff --git a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php index 058f83b..74d6c3b 100644 --- a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php +++ b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php @@ -50,6 +50,7 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_no_label'); + $this->installEntitySchema('node'); /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */ $storage = $this->container->get('entity.manager') diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyVocabularyTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyVocabularyTest.php index 5663ea6..115a04f 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyVocabularyTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyVocabularyTest.php @@ -16,7 +16,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} */ - public static $modules = ['taxonomy']; + public static $modules = ['taxonomy', 'text']; /** * {@inheritdoc} diff --git a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php index a9f4c47..dd483ce 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTestBase.php @@ -76,6 +76,7 @@ protected function setUp($import_test_views = TRUE) { parent::setUp($import_test_views); // Install node config to create body field. + $this->installEntitySchema('node'); $this->installConfig(['node', 'filter']); $this->installEntitySchema('user'); $this->installEntitySchema('taxonomy_term'); diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php index f61c856..7d2fe44 100644 --- a/core/modules/views/tests/src/Kernel/ModuleTest.php +++ b/core/modules/views/tests/src/Kernel/ModuleTest.php @@ -139,6 +139,7 @@ public function customErrorHandler($error_level, $message, $filename, $line, $co */ public function testLoadFunctions() { $this->enableModules(['text', 'node']); + $this->installEntitySchema('node'); $this->installConfig(['node']); $storage = $this->container->get('entity.manager')->getStorage('view'); diff --git a/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php b/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php index 294bb0f..5d6b078 100644 --- a/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php +++ b/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php @@ -31,6 +31,7 @@ class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase { protected function setUp($import_test_views = TRUE) { parent::setUp($import_test_views); + $this->installEntitySchema('entity_test'); $this->installEntitySchema('user'); $this->installSchema('user', ['users_data']); } diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php index 7854402..c5292df 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php @@ -70,16 +70,16 @@ protected function setUp() { $this->entityTypeManager = \Drupal::entityTypeManager(); - $this->installConfig(['filter', 'node', 'system']); - - $this->installSchema('system', ['key_value_expire', 'sequences']); - $this->installSchema('node', ['node_access']); - $this->installEntitySchema('entity_test_mulrev'); $this->installEntitySchema('entity_test_mulrevpub'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); + $this->installConfig(['filter', 'node', 'system']); + + $this->installSchema('system', ['key_value_expire', 'sequences']); + $this->installSchema('node', ['node_access']); + $this->createContentType(['type' => 'page']); $this->setCurrentUser($this->createUser(['administer nodes'])); diff --git a/core/tests/Drupal/KernelTests/Core/Datetime/TimestampSchemaTest.php b/core/tests/Drupal/KernelTests/Core/Datetime/TimestampSchemaTest.php index 43fbd42..977f8af 100644 --- a/core/tests/Drupal/KernelTests/Core/Datetime/TimestampSchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Datetime/TimestampSchemaTest.php @@ -14,7 +14,15 @@ class TimestampSchemaTest extends KernelTestBase { /** * {@inheritdoc} */ - protected static $modules = ['entity_test', 'field', 'field_timestamp_test']; + protected static $modules = ['entity_test', 'field', 'field_timestamp_test', 'user']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('entity_test'); + } /** * Tests if the timestamp field schema is validated. diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index 1a743ec..56fc5de 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -779,52 +779,6 @@ public function testDefinitionEvents() { } /** - * Tests updating entity schema and creating a base field. - * - * This tests updating entity schema and creating a base field at the same - * time when there are no existing entities. - */ - public function testEntityTypeSchemaUpdateAndBaseFieldCreateWithoutData() { - $this->updateEntityTypeToRevisionable(); - $this->addBaseField(); - $message = 'Successfully updated entity schema and created base field at the same time.'; - // Entity type updates create base fields as well, thus make sure doing both - // at the same time does not lead to errors due to the base field being - // created twice. - try { - $this->entityDefinitionUpdateManager->applyUpdates(); - $this->pass($message); - } - catch (\Exception $e) { - $this->fail($message); - throw $e; - } - } - - /** - * Tests updating entity schema and creating a revisionable base field. - * - * This tests updating entity schema and creating a revisionable base field - * at the same time when there are no existing entities. - */ - public function testEntityTypeSchemaUpdateAndRevisionableBaseFieldCreateWithoutData() { - $this->updateEntityTypeToRevisionable(); - $this->addRevisionableBaseField(); - $message = 'Successfully updated entity schema and created revisionable base field at the same time.'; - // Entity type updates create base fields as well, thus make sure doing both - // at the same time does not lead to errors due to the base field being - // created twice. - try { - $this->entityDefinitionUpdateManager->applyUpdates(); - $this->pass($message); - } - catch (\Exception $e) { - $this->fail($message); - throw $e; - } - } - - /** * Tests applying single updates. */ public function testSingleActionCalls() { @@ -853,13 +807,6 @@ public function testSingleActionCalls() { $this->pass($message); } - // Ensure that a non-existing field cannot be installed. - $storage_definition = BaseFieldDefinition::create('string') - ->setLabel(t('A new revisionable base field')) - ->setRevisionable(TRUE); - $this->entityDefinitionUpdateManager->installFieldStorageDefinition('bar', 'entity_test_update', 'entity_test', $storage_definition); - $this->assertFalse($db_schema->fieldExists('entity_test_update', 'bar'), "A non-existing field cannot be installed."); - // Ensure that installing an existing entity type is a no-op. $entity_type = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update'); $this->entityDefinitionUpdateManager->installEntityType($entity_type); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php index ec1a55c..258301f 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php @@ -18,7 +18,17 @@ class EntityDisplayBaseTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['entity_test', 'entity_test_third_party', 'field', 'system', 'comment']; + public static $modules = ['entity_test', 'entity_test_third_party', 'field', 'system', 'comment', 'user']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('comment'); + $this->installEntitySchema('entity_test'); + $this->installSchema('user', ['users_data']); + } /** * @covers ::preSave diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php index f7108d5..ae8e245 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php @@ -70,8 +70,8 @@ protected function setUp() { // enabled in. The comment, node and taxonomy config and the // taxonomy_term schema need to be installed before the forum config // which in turn needs to be installed before field config. - $this->installConfig(['comment', 'node', 'taxonomy']); $this->installEntitySchema('taxonomy_term'); + $this->installConfig(['comment', 'node', 'taxonomy']); $this->installConfig(['forum']); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php index 2a6dfed..4a16305 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php @@ -44,6 +44,13 @@ protected function setUp() { ConfigurableLanguage::createFromLangcode('de') ->save(); + $this->installEntitySchema('entity_test_mul'); + $this->installEntitySchema('entity_test_mul_langcode_key'); + $this->installEntitySchema('entity_test_mul_changed'); + $this->installEntitySchema('entity_test_rev'); + $this->installEntitySchema('entity_test_mulrev'); + $this->installEntitySchema('entity_test_mulrev_changed'); + // Create the test field. module_load_install('entity_test'); entity_test_install(); diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php index f273029..3b88a97 100644 --- a/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php +++ b/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php @@ -35,6 +35,15 @@ protected function setUp() { parent::setUp(); // Install field configuration. $this->installConfig(['field']); + + $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_mul'); + $this->installEntitySchema('entity_test_mul_langcode_key'); + $this->installEntitySchema('entity_test_mul_changed'); + $this->installEntitySchema('entity_test_rev'); + $this->installEntitySchema('entity_test_mulrev'); + $this->installEntitySchema('entity_test_mulrev_changed'); + // The users table is needed for creating dummy user accounts. $this->installEntitySchema('user'); // Register entity_test text field. diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index cf18e2b..5926cfd 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -367,12 +367,9 @@ public function testGetSchemaBase() { $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); $table_mapping->setExtraColumns('entity_test', ['default_langcode']); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); $this->assertNull( $this->storageSchema->onEntityTypeCreate($this->entityType) @@ -478,12 +475,9 @@ public function testGetSchemaRevisionable() { $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); $table_mapping->setFieldNames('entity_test_revision', array_keys($this->storageDefinitions)); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); $this->storageSchema->onEntityTypeCreate($this->entityType); } @@ -589,12 +583,9 @@ public function testGetSchemaTranslatable() { $table_mapping->setFieldNames('entity_test', $non_data_fields); $table_mapping->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions)); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); $this->assertNull( $this->storageSchema->onEntityTypeCreate($this->entityType) @@ -812,12 +803,9 @@ public function testGetSchemaRevisionableTranslatable() { $table_mapping->setFieldNames('entity_test_field_data', array_keys($this->storageDefinitions)); $table_mapping->setFieldNames('entity_test_revision_field_data', array_keys($this->storageDefinitions)); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); $this->storageSchema->onEntityTypeCreate($this->entityType); } @@ -990,7 +978,7 @@ public function testDedicatedTableSchema() { $table_mapping->setFieldNames($entity_type_id, array_keys($this->storageDefinitions)); $table_mapping->setExtraColumns($entity_type_id, ['default_langcode']); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); @@ -1135,7 +1123,7 @@ public function testDedicatedTableSchemaForEntityWithStringIdentifier() { $table_mapping->setFieldNames($entity_type_id, array_keys($this->storageDefinitions)); $table_mapping->setExtraColumns($entity_type_id, ['default_langcode']); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); @@ -1312,12 +1300,9 @@ public function testRequiresEntityStorageSchemaChanges(ContentEntityTypeInterfac $table_mapping = new DefaultTableMapping($this->entityType, $this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); $table_mapping->setExtraColumns('entity_test', ['default_langcode']); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); // Setup storage schema. if ($change_schema) { @@ -1356,11 +1341,15 @@ public function testRequiresEntityStorageSchemaChanges(ContentEntityTypeInterfac */ protected function setUpStorageSchema(array $expected = []) { $this->entityManager->expects($this->any()) - ->method('getDefinition') + ->method('getLastInstalledDefinition') ->with($this->entityType->id()) ->will($this->returnValue($this->entityType)); $this->entityManager->expects($this->any()) + ->method('getLastInstalledFieldStorageDefinitions') + ->with($this->entityType->id()) + ->will($this->returnValue($this->storageDefinitions)); + $this->entityManager->expects($this->any()) ->method('getFieldStorageDefinitions') ->with($this->entityType->id()) ->will($this->returnValue($this->storageDefinitions)); @@ -1399,7 +1388,7 @@ protected function setUpStorageSchema(array $expected = []) { $key_value = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); $this->storageSchema = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema') ->setConstructorArgs([$this->entityManager, $this->entityType, $this->storage, $connection]) - ->setMethods(['installedStorageSchema', 'loadEntitySchemaData', 'hasSharedTableNameChanges', 'isTableEmpty']) + ->setMethods(['installedStorageSchema', 'loadEntitySchemaData', 'hasSharedTableNameChanges', 'isTableEmpty', 'getTableMapping']) ->getMock(); $this->storageSchema ->expects($this->any()) @@ -1499,12 +1488,9 @@ public function testonEntityTypeUpdateWithNewIndex() { $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); $table_mapping->setExtraColumns('entity_test', ['default_langcode']); - $this->storage->expects($this->any()) + $this->storageSchema->expects($this->any()) ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->storage->expects($this->any()) - ->method('getCustomTableMapping') - ->will($this->returnValue($table_mapping)); $this->storageSchema->expects($this->any()) ->method('loadEntitySchemaData') diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 376b556..7512eec 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\MemoryCache\MemoryCache; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -70,6 +71,13 @@ class SqlContentEntityStorageTest extends UnitTestCase { protected $entityFieldManager; /** + * The mocked entity last installed schema repository used in this test. + * + * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $entityLastInstalledSchemaRepository; + + /** * The entity type ID. * * @var string @@ -129,6 +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->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); @@ -142,6 +151,7 @@ protected function setUp() { $this->container->set('entity.manager', $this->entityManager); $this->container->set('entity_type.manager', $this->entityTypeManager); $this->container->set('entity_field.manager', $this->entityFieldManager); + $this->container->set('entity.last_installed_schema.repository', $this->entityLastInstalledSchemaRepository); } /** @@ -862,6 +872,8 @@ public function testGetTableMappingRevisionableTranslatable(array $entity_keys) ->method('getRevisionMetadataKeys') ->will($this->returnValue($revision_metadata_keys)); + $this->fieldDefinitions = $this->mockFieldDefinitions(array_values($revision_metadata_keys), ['isRevisionable' => TRUE]); + $this->setUpEntityStorage(); $mapping = $this->entityStorage->getTableMapping(); @@ -1170,6 +1182,14 @@ protected function setUpEntityStorage() { ->method('getBaseFieldDefinitions') ->will($this->returnValue($this->fieldDefinitions)); + $this->entityLastInstalledSchemaRepository->expects($this->any()) + ->method('getLastInstalledDefinition') + ->will($this->returnValue($this->entityType)); + + $this->entityLastInstalledSchemaRepository->expects($this->any()) + ->method('getLastInstalledFieldStorageDefinitions') + ->will($this->returnValue($this->fieldDefinitions)); + $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager, new MemoryCache()); }