Commit 85860ba3 authored by alexpott's avatar alexpott

Issue #2858109 by amateescu: The BlockContent entity type does not specify its revision data table

parent f974370a
......@@ -162,11 +162,19 @@ protected function hasSharedTableStructureChange(EntityTypeInterface $entity_typ
* Returns TRUE if there have been changes.
*/
protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
$base_table = $this->database->schema()->tableExists($entity_type->getBaseTable());
$data_table = $this->database->schema()->tableExists($entity_type->getDataTable());
$revision_table = $this->database->schema()->tableExists($entity_type->getRevisionTable());
$revision_data_table = $this->database->schema()->tableExists($entity_type->getRevisionDataTable());
// We first check if the new table already exists because the storage might
// have created it even though it wasn't specified in the entity type
// definition.
return
$entity_type->getBaseTable() != $original->getBaseTable() ||
$entity_type->getDataTable() != $original->getDataTable() ||
$entity_type->getRevisionTable() != $original->getRevisionTable() ||
$entity_type->getRevisionDataTable() != $original->getRevisionDataTable();
(!$base_table && $entity_type->getBaseTable() != $original->getBaseTable()) ||
(!$data_table && $entity_type->getDataTable() != $original->getDataTable()) ||
(!$revision_table && $entity_type->getRevisionTable() != $original->getRevisionTable()) ||
(!$revision_data_table && $entity_type->getRevisionDataTable() != $original->getRevisionDataTable());
}
/**
......
......@@ -61,3 +61,14 @@ function block_content_update_8003() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
}
/**
* Fix the block_content entity type to specify its revision data table.
*/
function block_content_update_8300() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $definition_update_manager->getEntityType('block_content');
$entity_type->set('revision_data_table', 'block_content_field_revision');
$definition_update_manager->updateEntityType($entity_type);
}
......@@ -35,6 +35,7 @@
* base_table = "block_content",
* revision_table = "block_content_revision",
* data_table = "block_content_field_data",
* revision_data_table = "block_content_field_revision",
* show_revision_ui = TRUE,
* links = {
* "canonical" = "/block/{block_content}",
......
......@@ -6,11 +6,11 @@
use Drupal\system\Tests\Update\UpdatePathTestBase;
/**
* Tests adding revision_user and revision_created fields.
* Tests update functions for the Block Content module.
*
* @group Update
*/
class BlockContentUpdateEntityFields extends UpdatePathTestBase {
class BlockContentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
......@@ -22,18 +22,25 @@ protected function setDatabaseDumpFiles() {
}
/**
* Tests that email token in status_blocked of user.mail is updated.
* Tests the revision metadata fields and revision data table additions.
*/
public function testAddingFields() {
public function testSimpleUpdates() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
$this->assertNull($entity_type->getRevisionDataTable());
$this->runUpdates();
$post_revision_created = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_created', 'block_content');
$post_revision_user = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_user', 'block_content');
$post_revision_created = $entity_definition_update_manager->getFieldStorageDefinition('revision_created', 'block_content');
$post_revision_user = $entity_definition_update_manager->getFieldStorageDefinition('revision_user', 'block_content');
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
$this->assertEqual('block_content_field_revision', $entity_type->getRevisionDataTable());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment