diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index 7555b45..0f91c66 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -186,8 +186,8 @@ public function initializeMapping() { } elseif ($revisionable && $translatable) { // The revisionable multilingual layout stores key field values in the - // base table, except for language, which is stored in the revision - // table along with revision metadata. The revision data table holds + // base table and the revision table holds the entity ID, revision ID and + // langcode ID along with revision metadata. The revision data table holds // data field values for all the revisionable fields and the data table // holds the data field values for all non-revisionable fields. The data // field values of revisionable fields are denormalized in the data diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index ad94f46..fd5ac4b 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -405,6 +405,22 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $ * {@inheritdoc} */ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition) { + // Only configurable fields currently support purging, so prevent deletion + // of ones we can't purge if they have existing data. + // @todo Add purging to all fields: https://www.drupal.org/node/2282119. + try { + if (!($storage_definition instanceof FieldStorageConfigInterface) && $this->storage->countFieldData($storage_definition, TRUE)) { + throw new FieldStorageDefinitionUpdateForbiddenException('Unable to delete a field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data that cannot be purged.'); + } + } + catch (DatabaseException $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; + } + // Retrieve a table mapping which contains the deleted field still. $table_mapping = $this->storage->getTableMapping( $this->entityManager->getLastInstalledFieldStorageDefinitions($this->entityType->id())