diff --git a/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php index 5d5f49f6e2..89ef413125 100644 --- a/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php @@ -83,14 +83,16 @@ public function getChangeSummary(); * Gets a list of changes to entity type and field storage definitions. * * @return array - * An associative array keyed by entity type id of change descriptors. Every + * An associative array keyed by entity type ID of change descriptors. Every * entry is an associative array with the following optional keys: - * - entity_type: a scalar having only the DEFINITION_UPDATED value. + * - entity_type: a scalar having one value among: + * - EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED + * - EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED * - field_storage_definitions: an associative array keyed by field name of * scalars having one value among: - * - DEFINITION_CREATED - * - DEFINITION_UPDATED - * - DEFINITION_DELETED + * - EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED + * - EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED + * - EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED */ public function getChangeList(); diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 388a6270d4..eb76f99eaa 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -181,9 +181,8 @@ 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\Entity\EntityTypeInterface $entity_type + * An 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. @@ -191,9 +190,7 @@ protected function deletedFieldsRepository() { * @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; - + protected function getTableMapping(EntityTypeInterface $entity_type, array $storage_definitions = NULL) { // Allow passing a single field storage definition when updating a field. if ($storage_definitions && count($storage_definitions) === 1) { $storage_definition = reset($storage_definitions); @@ -266,7 +263,7 @@ protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, E * {@inheritdoc} */ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - $table_mapping = $this->getTableMapping(); + $table_mapping = $this->getTableMapping($this->entityType); if ( $storage_definition->hasCustomStorage() != $original->hasCustomStorage() || @@ -306,7 +303,7 @@ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterfac */ protected function getSchemaFromStorageDefinition(FieldStorageDefinitionInterface $storage_definition) { assert(!$storage_definition->hasCustomStorage()); - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $schema = []; if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { $schema = $this->getDedicatedTableSchema($storage_definition); @@ -373,7 +370,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { } // Create dedicated field tables. - $table_mapping = $this->getTableMapping(); + $table_mapping = $this->getTableMapping($this->entityType); foreach ($this->fieldStorageDefinitions as $field_storage_definition) { if ($table_mapping->requiresDedicatedTableStorage($field_storage_definition)) { $this->createDedicatedTableSchema($field_storage_definition); @@ -647,7 +644,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ return; } - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $field_table_name = $table_mapping->getFieldTableName($storage_definition->getName()); if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { @@ -669,7 +666,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $ // Refresh the table mapping to use the deleted storage definition. $deleted_storage_definition = $this->deletedFieldsRepository()->getFieldStorageDefinitions()[$storage_definition->getUniqueStorageIdentifier()]; - $table_mapping = $this->getTableMapping(NULL, [$deleted_storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$deleted_storage_definition]); $dedicated_table_field_schema = $this->getDedicatedTableSchema($deleted_storage_definition); $dedicated_table_field_columns = $table_mapping->getColumnNames($deleted_storage_definition->getName()); @@ -1477,7 +1474,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->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { $this->{$operation . 'DedicatedTableSchema'}($storage_definition, $original); } @@ -1525,7 +1522,7 @@ protected function createDedicatedTableSchema(FieldStorageDefinitionInterface $s */ protected function createSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, $only_save = FALSE) { $created_field_name = $storage_definition->getName(); - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$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()); @@ -1597,7 +1594,7 @@ protected function createSharedTableSchema(FieldStorageDefinitionInterface $stor * The storage definition of the field being deleted. */ protected function deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition) { - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$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); @@ -1622,7 +1619,7 @@ protected function deleteSharedTableSchema(FieldStorageDefinitionInterface $stor $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($this->entityType), $storage_definition); $deleted_field_name = $storage_definition->getName(); - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$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()); @@ -1703,7 +1700,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->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $table = $table_mapping->getDedicatedDataTableName($original); $revision_table = $table_mapping->getDedicatedRevisionTableName($original); @@ -1793,7 +1790,7 @@ protected function updateSharedTableSchema(FieldStorageDefinitionInterface $stor } $updated_field_name = $storage_definition->getName(); - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $column_names = $table_mapping->getColumnNames($updated_field_name); $schema_handler = $this->database->schema(); @@ -1868,7 +1865,7 @@ protected function createEntitySchemaIndexes(array $entity_schema, FieldStorageD $schema_handler = $this->database->schema(); if ($storage_definition) { - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $column_names = $table_mapping->getColumnNames($storage_definition->getName()); } @@ -1927,7 +1924,7 @@ protected function deleteEntitySchemaIndexes(array $entity_schema_data, FieldSto $schema_handler = $this->database->schema(); if ($storage_definition) { - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $column_names = $table_mapping->getColumnNames($storage_definition->getName()); } @@ -2001,7 +1998,7 @@ protected function hasNullFieldPropertyData($table_name, $column_name) { */ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) { $schema = []; - $table_mapping = $this->getTableMapping(NULL, [$storage_definition]); + $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]); $field_schema = $storage_definition->getSchema(); // Check that the schema does not include forbidden column names. diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrateDrupalTestBase.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrateDrupalTestBase.php index 063c99cb36..f361fb16ef 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/MigrateDrupalTestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrateDrupalTestBase.php @@ -22,7 +22,21 @@ */ protected function setUp() { parent::setUp(); - $this->installEntitySchema('user'); + + $module_handler = \Drupal::moduleHandler(); + if ($module_handler->moduleExists('node')) { + $this->installEntitySchema('node'); + } + if ($module_handler->moduleExists('comment')) { + $this->installEntitySchema('comment'); + } + if ($module_handler->moduleExists('taxonomy')) { + $this->installEntitySchema('taxonomy_term'); + } + if ($module_handler->moduleExists('user')) { + $this->installEntitySchema('user'); + } + $this->installConfig(['migrate_drupal', 'system']); } 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 58ca6f0b8a..0b2735c8ea 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6TestBase.php @@ -29,17 +29,6 @@ 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 dc35aa0cc0..535421cd84 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7TestBase.php @@ -15,19 +15,6 @@ 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'); - } } /**