summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-02-23 13:45:30 +0000
committerNathaniel Catchpole2017-02-23 13:45:30 +0000
commit4b325ae0c70959714325fbec811b359894cd1d27 (patch)
tree778e5cf7964fa369bbe5e2822d25d457917ba91a
parent801f6ca130b5776cb032f6dbd5b4aad69b39e079 (diff)
Issue #2248983 by hchonov, amateescu, paranojik, timmillwood, tstoeckler, catch, Berdir, alexpott: Define the revision metadata base fields in the entity annotation in order for the storage to create them only in the revision table
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityType.php47
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityTypeInterface.php46
-rw-r--r--core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php48
-rw-r--r--core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php14
-rw-r--r--core/modules/block_content/src/Entity/BlockContent.php5
-rw-r--r--core/modules/node/src/Entity/Node.php5
-rw-r--r--core/modules/system/src/Tests/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php83
-rw-r--r--core/modules/system/system.install138
-rw-r--r--core/modules/system/tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gzbin0 -> 142952 bytes
-rw-r--r--core/modules/system/tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php162
-rw-r--r--core/modules/system/tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php35
-rw-r--r--core/modules/system/tests/fixtures/update/views.view.entity_test_mul_revlog_for_2248983.yml435
-rw-r--r--core/modules/system/tests/fixtures/update/views.view.entity_test_revlog_for_2248983.yml436
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithRevisionLog.php48
-rw-r--r--core/modules/system/tests/modules/entity_test_revlog/entity_test_revlog.info.yml6
-rw-r--r--core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php33
-rw-r--r--core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestWithRevisionLog.php59
-rw-r--r--core/modules/views/src/Entity/View.php50
-rw-r--r--core/modules/views/tests/src/Unit/EntityViewsDataTest.php3
-rw-r--r--core/modules/views/views.post_update.php21
-rw-r--r--core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php6
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php55
-rw-r--r--sites/default/default.settings.php10
23 files changed, 1650 insertions, 95 deletions
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityType.php b/core/lib/Drupal/Core/Entity/ContentEntityType.php
index 6d8d619..6103a56 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityType.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php
@@ -8,6 +8,13 @@ namespace Drupal\Core\Entity;
class ContentEntityType extends EntityType implements ContentEntityTypeInterface {
/**
+ * An array of entity revision metadata keys.
+ *
+ * @var array
+ */
+ protected $revision_metadata_keys = [];
+
+ /**
* {@inheritdoc}
*/
public function __construct($definition) {
@@ -41,4 +48,44 @@ class ContentEntityType extends EntityType implements ContentEntityTypeInterface
}
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getRevisionMetadataKeys($include_backwards_compatibility_field_names = TRUE) {
+ // Provide backwards compatibility in case the revision metadata keys are
+ // not defined in the entity annotation.
+ if (!$this->revision_metadata_keys && $include_backwards_compatibility_field_names) {
+ $base_fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($this->id());
+ if ((isset($base_fields['revision_uid']) && $revision_user = 'revision_uid') || (isset($base_fields['revision_user']) && $revision_user = 'revision_user')) {
+ @trigger_error('The revision_user revision metadata key is not set.', E_USER_DEPRECATED);
+ $this->revision_metadata_keys['revision_user'] = $revision_user;
+ }
+ if ((isset($base_fields['revision_timestamp']) && $revision_timestamp = 'revision_timestamp') || (isset($base_fields['revision_created'])) && $revision_timestamp = 'revision_created') {
+ @trigger_error('The revision_created revision metadata key is not set.', E_USER_DEPRECATED);
+ $this->revision_metadata_keys['revision_created'] = $revision_timestamp;
+ }
+ if ((isset($base_fields['revision_log']) && $revision_log = 'revision_log') || (isset($base_fields['revision_log_message']) && $revision_log = 'revision_log_message')) {
+ @trigger_error('The revision_log_message revision metadata key is not set.', E_USER_DEPRECATED);
+ $this->revision_metadata_keys['revision_log_message'] = $revision_log;
+ }
+ }
+ return $this->revision_metadata_keys;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRevisionMetadataKey($key) {
+ $keys = $this->getRevisionMetadataKeys();
+ return isset($keys[$key]) ? $keys[$key] : FALSE;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasRevisionMetadataKey($key) {
+ $keys = $this->getRevisionMetadataKeys();
+ return isset($keys[$key]);
+ }
+
}
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityTypeInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityTypeInterface.php
index f9ef160..4c9e890 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityTypeInterface.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityTypeInterface.php
@@ -6,4 +6,50 @@ namespace Drupal\Core\Entity;
* Provides an interface for a content entity type and its metadata.
*/
interface ContentEntityTypeInterface extends EntityTypeInterface {
+
+ /**
+ * Gets an array of entity revision metadata keys.
+ *
+ * @param bool $include_backwards_compatibility_field_names
+ * (optional and deprecated) Whether to provide the revision keys on a
+ * best-effort basis by looking at the base fields defined by the entity
+ * type. Note that this parameter will be removed in Drupal 9.0.0. Defaults
+ * to TRUE.
+ *
+ * @return array
+ * An array describing how the Field API can extract revision metadata
+ * information of this entity type:
+ * - revision_log_message: The name of the property that contains description
+ * of the changes that were made in the current revision.
+ * - revision_user: The name of the property that contains the user ID of
+ * the author of the current revision.
+ * - revision_created: The name of the property that contains the timestamp
+ * of the current revision.
+ */
+ public function getRevisionMetadataKeys($include_backwards_compatibility_field_names = TRUE);
+
+ /**
+ * Gets a specific entity revision metadata key.
+ *
+ * @param string $key
+ * The name of the entity revision metadata key to return.
+ *
+ * @return string|bool
+ * The entity revision metadata key, or FALSE if it does not exist.
+ *
+ * @see self::getRevisionMetadataKeys()
+ */
+ public function getRevisionMetadataKey($key);
+
+ /**
+ * Indicates if a given entity revision metadata key exists.
+ *
+ * @param string $key
+ * The name of the entity revision metadata key to check.
+ *
+ * @return bool
+ * TRUE if a given entity revision metadata key exists, FALSE otherwise.
+ */
+ public function hasRevisionMetadataKey($key);
+
}
diff --git a/core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php b/core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php
index 7392858..f935a8b 100644
--- a/core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php
+++ b/core/lib/Drupal/Core/Entity/RevisionLogEntityTrait.php
@@ -25,18 +25,18 @@ trait RevisionLogEntityTrait {
* @see \Drupal\Core\Entity\FieldableEntityInterface::baseFieldDefinitions()
*/
public static function revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type) {
- $fields['revision_created'] = BaseFieldDefinition::create('created')
+ $fields[static::getRevisionMetadataKey($entity_type, 'revision_created')] = BaseFieldDefinition::create('created')
->setLabel(t('Revision create time'))
->setDescription(t('The time that the current revision was created.'))
->setRevisionable(TRUE);
- $fields['revision_user'] = BaseFieldDefinition::create('entity_reference')
+ $fields[static::getRevisionMetadataKey($entity_type, 'revision_user')] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setRevisionable(TRUE);
- $fields['revision_log_message'] = BaseFieldDefinition::create('string_long')
+ $fields[static::getRevisionMetadataKey($entity_type, 'revision_log_message')] = BaseFieldDefinition::create('string_long')
->setLabel(t('Revision log message'))
->setDescription(t('Briefly describe the changes you have made.'))
->setRevisionable(TRUE)
@@ -56,14 +56,14 @@ trait RevisionLogEntityTrait {
* Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime().
*/
public function getRevisionCreationTime() {
- return $this->revision_created->value;
+ return $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_created')}->value;
}
/**
* Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime().
*/
public function setRevisionCreationTime($timestamp) {
- $this->revision_created->value = $timestamp;
+ $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_created')}->value = $timestamp;
return $this;
}
@@ -71,14 +71,14 @@ trait RevisionLogEntityTrait {
* Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser().
*/
public function getRevisionUser() {
- return $this->revision_user->entity;
+ return $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_user')}->entity;
}
/**
* Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser().
*/
public function setRevisionUser(UserInterface $account) {
- $this->revision_user->entity = $account;
+ $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_user')}->entity = $account;
return $this;
}
@@ -86,14 +86,14 @@ trait RevisionLogEntityTrait {
* Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId().
*/
public function getRevisionUserId() {
- return $this->revision_user->target_id;
+ return $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_user')}->target_id;
}
/**
* Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId().
*/
public function setRevisionUserId($user_id) {
- $this->revision_user->target_id = $user_id;
+ $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_user')}->target_id = $user_id;
return $this;
}
@@ -101,15 +101,41 @@ trait RevisionLogEntityTrait {
* Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage().
*/
public function getRevisionLogMessage() {
- return $this->revision_log_message->value;
+ return $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_log_message')}->value;
}
/**
* Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage().
*/
public function setRevisionLogMessage($revision_log_message) {
- $this->revision_log_message->value = $revision_log_message;
+ $this->{static::getRevisionMetadataKey($this->getEntityType(), 'revision_log_message')}->value = $revision_log_message;
return $this;
}
+ /**
+ * Gets the name of a revision metadata field.
+ *
+ * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
+ * A content entity type definition.
+ * @param string $key
+ * The revision metadata key to get, must be one of 'revision_created',
+ * 'revision_user' or 'revision_log_message'.
+ *
+ * @return string
+ * The name of the field for the specified $key.
+ */
+ protected static function getRevisionMetadataKey(EntityTypeInterface $entity_type, $key) {
+ // We need to prevent ContentEntityType::getRevisionMetadataKey() from
+ // providing fallback as that requires fetching the entity type's field
+ // definition leading to an infinite recursion.
+ /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
+ $revision_metadata_keys = $entity_type->getRevisionMetadataKeys(FALSE) + [
+ 'revision_created' => 'revision_created',
+ 'revision_user' => 'revision_user',
+ 'revision_log_message' => 'revision_log_message',
+ ];
+
+ return $revision_metadata_keys[$key];
+ }
+
}
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index 8031830..5c03b65 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -294,17 +294,11 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
// Make sure the key fields come first in the list of fields.
$all_fields = array_merge($key_fields, array_diff($all_fields, $key_fields));
- // Nodes have all three of these fields, while custom blocks only have
- // log.
- // @todo Provide automatic definitions for revision metadata fields in
- // https://www.drupal.org/node/2248983.
- $revision_metadata_fields = array_intersect(array(
- 'revision_timestamp',
- 'revision_uid',
- 'revision_log',
- ), $all_fields);
-
+ // If the entity is revisionable, gather the fields that need to be put
+ // in the revision table.
$revisionable = $this->entityType->isRevisionable();
+ $revision_metadata_fields = $revisionable ? array_values($this->entityType->getRevisionMetadataKeys()) : [];
+
$translatable = $this->entityType->isTranslatable();
if (!$revisionable && !$translatable) {
// The base layout stores all the base field values in the base table.
diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php
index 51ae6f6..7c06ed8 100644
--- a/core/modules/block_content/src/Entity/BlockContent.php
+++ b/core/modules/block_content/src/Entity/BlockContent.php
@@ -51,6 +51,11 @@ use Drupal\user\UserInterface;
* "langcode" = "langcode",
* "uuid" = "uuid"
* },
+ * revision_metadata_keys = {
+ * "revision_user" = "revision_user",
+ * "revision_created" = "revision_created",
+ * "revision_log_message" = "revision_log"
+ * },
* bundle_entity_type = "block_content_type",
* field_ui_base_route = "entity.block_content_type.edit_form",
* render_cache = FALSE,
diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php
index 0edb58f..13192cf 100644
--- a/core/modules/node/src/Entity/Node.php
+++ b/core/modules/node/src/Entity/Node.php
@@ -61,6 +61,11 @@ use Drupal\user\UserInterface;
* "published" = "status",
* "uid" = "uid",
* },
+ * revision_metadata_keys = {
+ * "revision_user" = "revision_uid",
+ * "revision_created" = "revision_timestamp",
+ * "revision_log_message" = "revision_log"
+ * },
* bundle_entity_type = "node_type",
* field_ui_base_route = "entity.node_type.edit_form",
* common_reference_target = TRUE,
diff --git a/core/modules/system/src/Tests/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php b/core/modules/system/src/Tests/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
new file mode 100644
index 0000000..457ced8
--- /dev/null
+++ b/core/modules/system/src/Tests/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Drupal\system\Tests\Entity\Update;
+
+use Drupal\system\Tests\Update\UpdatePathTestBase;
+use Drupal\views\Entity\View;
+
+/**
+ * Tests the upgrade path for moving the revision metadata fields.
+ *
+ * @group Update
+ */
+class MoveRevisionMetadataFieldsUpdateTest extends UpdatePathTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setDatabaseDumpFiles() {
+ $this->databaseDumpFiles = [
+ __DIR__ . '/../../../../tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz',
+ __DIR__ . '/../../../../tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php',
+ __DIR__ . '/../../../../tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php',
+ ];
+ }
+
+ /**
+ * Tests that the revision metadata fields are moved correctly.
+ */
+ public function testSystemUpdate3000() {
+ $this->runUpdates();
+
+ foreach (['entity_test_revlog', 'entity_test_mul_revlog'] as $entity_type_id) {
+ /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
+ $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
+ /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
+ $entity_type = $storage->getEntityType();
+ $revision_metadata_field_names = $entity_type->getRevisionMetadataKeys();
+
+ $database_schema = \Drupal::database()->schema();
+
+ // Test that the revision metadata fields are present only in the
+ // revision table.
+ foreach ($revision_metadata_field_names as $revision_metadata_field_name) {
+ if ($entity_type->isTranslatable()) {
+ $this->assertFalse($database_schema->fieldExists($entity_type->getDataTable(), $revision_metadata_field_name));
+ $this->assertFalse($database_schema->fieldExists($entity_type->getRevisionDataTable(), $revision_metadata_field_name));
+ }
+ else {
+ $this->assertFalse($database_schema->fieldExists($entity_type->getBaseTable(), $revision_metadata_field_name));
+ }
+ $this->assertTrue($database_schema->fieldExists($entity_type->getRevisionTable(), $revision_metadata_field_name));
+ }
+
+ // Test that the revision metadata values have been transferred correctly
+ // and that the moved fields are accessible.
+ /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_first */
+ $entity_rev_first = $storage->loadRevision(1);
+ $this->assertEqual($entity_rev_first->getRevisionUserId(), '1');
+ $this->assertEqual($entity_rev_first->getRevisionLogMessage(), 'first revision');
+ $this->assertEqual($entity_rev_first->getRevisionCreationTime(), '1476268517');
+
+ /** @var \Drupal\Core\Entity\RevisionLogInterface $entity_rev_second */
+ $entity_rev_second = $storage->loadRevision(2);
+ $this->assertEqual($entity_rev_second->getRevisionUserId(), '1');
+ $this->assertEqual($entity_rev_second->getRevisionLogMessage(), 'second revision');
+ $this->assertEqual($entity_rev_second->getRevisionCreationTime(), '1476268518');
+
+
+ // Test that the views using revision metadata fields are updated
+ // properly.
+ $view = View::load($entity_type_id . '_for_2248983');
+ $displays = $view->get('display');
+ foreach ($displays as $display => $display_data) {
+ foreach ($display_data['display_options']['fields'] as $property_data) {
+ if (in_array($property_data['field'], $revision_metadata_field_names)) {
+ $this->assertEqual($property_data['table'], $entity_type->getRevisionTable());
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index d022f6a..059f097 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -12,6 +12,9 @@ use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Path\AliasStorage;
use Drupal\Core\Url;
use Drupal\Core\Database\Database;
+use Drupal\Core\Entity\ContentEntityTypeInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PrivateStream;
@@ -1832,5 +1835,140 @@ function system_update_8301() {
}
/**
+ * Move revision metadata fields to the revision table.
+ */
+function system_update_8302(&$sandbox) {
+ // Due to the fields from RevisionLogEntityTrait not being explicitly
+ // mentioned in the storage they might have been installed wrongly in the base
+ // table for revisionable untranslatable entities and in the data and revision
+ // data tables for revisionable and translatable entities.
+ $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
+ $database = \Drupal::database();
+ $database_schema = $database->schema();
+
+ if (!isset($sandbox['current'])) {
+ // This must be the first run. Initialize the sandbox.
+ $sandbox['current'] = 0;
+
+ $definitions = array_filter(\Drupal::entityTypeManager()->getDefinitions(), function (EntityTypeInterface $entity_type) use ($entity_definition_update_manager) {
+ if ($entity_type = $entity_definition_update_manager->getEntityType($entity_type->id())) {
+ return is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) && ($entity_type instanceof ContentEntityTypeInterface) && $entity_type->isRevisionable();
+ }
+ return FALSE;
+ });
+ $sandbox['entity_type_ids'] = array_keys($definitions);
+ $sandbox['max'] = count($sandbox['entity_type_ids']);
+ }
+
+ $current_entity_type_key = $sandbox['current'];
+ for ($i = $current_entity_type_key; ($i < $current_entity_type_key + 1) && ($i < $sandbox['max']); $i++) {
+ $entity_type_id = $sandbox['entity_type_ids'][$i];
+ /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
+ $entity_type = $entity_definition_update_manager->getEntityType($entity_type_id);
+
+ $base_fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
+ $revision_metadata_fields = $entity_type->getRevisionMetadataKeys();
+ $fields_to_update = array_intersect_key($base_fields, array_flip($revision_metadata_fields));
+
+ if (!empty($fields_to_update)) {
+ // Initialize the entity table names.
+ // @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage::initTableLayout()
+ $base_table = $entity_type->getBaseTable() ?: $entity_type_id;
+ $data_table = $entity_type->getDataTable() ?: $entity_type_id . '_field_data';
+ $revision_table = $entity_type->getRevisionTable() ?: $entity_type_id . '_revision';
+ $revision_data_table = $entity_type->getRevisionDataTable() ?: $entity_type_id . '_field_revision';
+ $revision_field = $entity_type->getKey('revision');
+
+ // No data needs to be migrated if the entity type is not translatable.
+ if ($entity_type->isTranslatable()) {
+ if (!isset($sandbox[$entity_type_id])) {
+ // This must be the first run for this entity type. Initialize the
+ // sub-sandbox for it.
+
+ // Calculate the number of revisions to process.
+ $count = \Drupal::entityQuery($entity_type_id)
+ ->allRevisions()
+ ->count()
+ ->accessCheck(FALSE)
+ ->execute();
+
+ $sandbox[$entity_type_id]['current'] = 0;
+ $sandbox[$entity_type_id]['max'] = $count;
+ }
+ // Define the step size.
+ $steps = Settings::get('entity_update_batch_size', 50);
+
+ // Collect the revision IDs to process.
+ $revisions = \Drupal::entityQuery($entity_type_id)
+ ->allRevisions()
+ ->range($sandbox[$entity_type_id]['current'], $sandbox[$entity_type_id]['current'] + $steps)
+ ->sort($revision_field, 'ASC')
+ ->accessCheck(FALSE)
+ ->execute();
+ $revisions = array_keys($revisions);
+
+ foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
+ // If the revision metadata field is present in the data and the
+ // revision data table, install its definition again with the updated
+ // storage code in order for the field to be installed in the
+ // revision table. Afterwards, copy over the field values and remove
+ // the field from the data and the revision data tables.
+ if ($database_schema->fieldExists($data_table, $revision_metadata_field_name) && $database_schema->fieldExists($revision_data_table, $revision_metadata_field_name)) {
+ // Install the field in the revision table.
+ if (!isset($sandbox[$entity_type_id]['storage_definition_installed'][$revision_metadata_field_name])) {
+ $entity_definition_update_manager->installFieldStorageDefinition($revision_metadata_field_name, $entity_type_id, $entity_type->getProvider(), $definition);
+ $sandbox[$entity_type_id]['storage_definition_installed'][$revision_metadata_field_name] = TRUE;
+ }
+
+ // Apply the field value from the revision data table to the
+ // revision table.
+ foreach ($revisions as $rev_id) {
+ $field_value = $database->select($revision_data_table, 't')
+ ->fields('t', [$revision_metadata_field_name])
+ ->condition($revision_field, $rev_id)
+ ->execute()
+ ->fetchField();
+ $database->update($revision_table)
+ ->condition($revision_field, $rev_id)
+ ->fields([$revision_metadata_field_name => $field_value])
+ ->execute();
+ }
+ }
+ }
+
+ $sandbox[$entity_type_id]['current'] += count($revisions);
+ $sandbox[$entity_type_id]['finished'] = ($sandbox[$entity_type_id]['current'] == $sandbox[$entity_type_id]['max']) || empty($revisions);
+
+ if ($sandbox[$entity_type_id]['finished']) {
+ foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
+ // Drop the field from the data and revision data tables.
+ $database_schema->dropField($data_table, $revision_metadata_field_name);
+ $database_schema->dropField($revision_data_table, $revision_metadata_field_name);
+ }
+ $sandbox['current']++;
+ }
+ }
+ else {
+ foreach ($fields_to_update as $revision_metadata_field_name => $definition) {
+ if ($database_schema->fieldExists($base_table, $revision_metadata_field_name)) {
+ // Install the field in the revision table.
+ $entity_definition_update_manager->installFieldStorageDefinition($revision_metadata_field_name, $entity_type_id, $entity_type->getProvider(), $definition);
+ // Drop the field from the base table.
+ $database_schema->dropField($base_table, $revision_metadata_field_name);
+ }
+ }
+ $sandbox['current']++;
+ }
+ }
+ else {
+ $sandbox['current']++;
+ }
+
+ }
+
+ $sandbox['#finished'] = $sandbox['current'] == $sandbox['max'];
+}
+
+/**
* @} End of "addtogroup updates-8.3.0".
*/
diff --git a/core/modules/system/tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz b/core/modules/system/tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz
new file mode 100644
index 0000000..1977264
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/drupal-8.2.0.bare.standard_with_entity_test_revlog_enabled.php.gz
Binary files differ
diff --git a/core/modules/system/tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php b/core/modules/system/tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php
new file mode 100644
index 0000000..0c537f5
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/drupal-8.entity-data-revision-metadata-fields-2248983.php
@@ -0,0 +1,162 @@
+<?php
+
+/**
+ * @file
+ * Contains database additions to
+ * drupal-8.2.1.bare.standard_with_entity_test_enabled.php.gz for testing the
+ * upgrade path of https://www.drupal.org/node/2248983.
+ */
+
+use Drupal\Core\Database\Database;
+
+$connection = Database::getConnection();
+
+// Data for entity type "entity_test_revlog"
+$connection->insert('entity_test_revlog')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'type',
+ 'uuid',
+ 'langcode',
+ 'revision_created',
+ 'revision_user',
+ 'revision_log_message',
+ 'name',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'type' => 'entity_test_revlog',
+ 'uuid' => 'f0b962b1-391b-441b-a664-2468ad520d96',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268518',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'second revision',
+ 'name' => 'entity 1',
+ ])
+ ->execute();
+
+$connection->insert('entity_test_revlog_revision')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'langcode',
+ 'revision_created',
+ 'revision_user',
+ 'revision_log_message',
+ 'name',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '1',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268517',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'first revision',
+ 'name' => 'entity 1',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268518',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'second revision',
+ 'name' => 'entity 1',
+ ])
+ ->execute();
+
+// Data for entity type "entity_test_mul_revlog"
+$connection->insert('entity_test_mul_revlog')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'type',
+ 'uuid',
+ 'langcode',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'type' => 'entity_test_mul_revlog',
+ 'uuid' => '6f04027a-1cbd-46e3-a67e-72636b493d4f',
+ 'langcode' => 'en',
+ ])
+ ->execute();
+
+$connection->insert('entity_test_mul_revlog_field_data')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'type',
+ 'langcode',
+ 'revision_created',
+ 'revision_user',
+ 'revision_log_message',
+ 'name',
+ 'default_langcode',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'type' => 'entity_test_mul_revlog',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268518',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'second revision',
+ 'name' => 'entity 1',
+ 'default_langcode' => '1',
+ ])
+ ->execute();
+
+$connection->insert('entity_test_mul_revlog_field_revision')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'langcode',
+ 'revision_created',
+ 'revision_user',
+ 'revision_log_message',
+ 'name',
+ 'default_langcode',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '1',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268517',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'first revision',
+ 'name' => 'entity 1',
+ 'default_langcode' => '1',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'langcode' => 'en',
+ 'revision_created' => '1476268518',
+ 'revision_user' => '1',
+ 'revision_log_message' => 'second revision',
+ 'name' => 'entity 1',
+ 'default_langcode' => '1',
+ ])
+ ->execute();
+
+$connection->insert('entity_test_mul_revlog_revision')
+ ->fields([
+ 'id',
+ 'revision_id',
+ 'langcode',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '1',
+ 'langcode' => 'en',
+ ])
+ ->values([
+ 'id' => '1',
+ 'revision_id' => '2',
+ 'langcode' => 'en',
+ ])
+ ->execute();
diff --git a/core/modules/system/tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php b/core/modules/system/tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php
new file mode 100644
index 0000000..59b05a5
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/drupal-8.views-revision-metadata-fields-2248983.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Contains database additions to
+ * drupal-8.2.1.bare.standard_with_entity_test_enabled.php.gz for testing the
+ * upgrade path of https://www.drupal.org/node/2248983.
+ */
+
+use Drupal\Core\Database\Database;
+use Drupal\Core\Serialization\Yaml;
+
+$connection = Database::getConnection();
+
+// View for the entity type "entity_test_revlog".
+$views_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/views.view.entity_test_revlog_for_2248983.yml'));
+
+// View for the entity type "entity_test_mul_revlog".
+$views_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/views.view.entity_test_mul_revlog_for_2248983.yml'));
+
+
+foreach ($views_configs as $views_config) {
+ $connection->insert('config')
+ ->fields(array(
+ 'collection',
+ 'name',
+ 'data',
+ ))
+ ->values(array(
+ 'collection' => '',
+ 'name' => 'views.view.' . $views_config['id'],
+ 'data' => serialize($views_config),
+ ))
+ ->execute();
+}
diff --git a/core/modules/system/tests/fixtures/update/views.view.entity_test_mul_revlog_for_2248983.yml b/core/modules/system/tests/fixtures/update/views.view.entity_test_mul_revlog_for_2248983.yml
new file mode 100644
index 0000000..d9eba9a
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/views.view.entity_test_mul_revlog_for_2248983.yml
@@ -0,0 +1,435 @@
+uuid: 25b89168-a8e5-4ae1-8fb5-c8efb91f0938
+langcode: en
+status: true
+dependencies:
+ module:
+ - entity_test_revlog
+id: entity_test_mul_revlog_for_2248983
+label: entity_test_mul_revlog
+module: views
+description: ''
+tag: ''
+base_table: entity_test_mul_revlog_property_data
+base_field: id
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 0
+ display_options:
+ access:
+ type: none
+ options: { }
+ cache:
+ type: tag
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ replica: false
+ query_comment: ''
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: mini
+ options:
+ items_per_page: 10
+ offset: 0
+ id: 0
+ total_pages: null
+ expose:
+ items_per_page: false
+ items_per_page_label: 'Items per page'
+ items_per_page_options: '5, 10, 25, 50'
+ items_per_page_options_all: false
+ items_per_page_options_all_label: '- All -'
+ offset: false
+ offset_label: Offset
+ tags:
+ previous: ‹‹
+ next: ››
+ style:
+ type: table
+ options:
+ grouping: { }
+ row_class: ''
+ default_row_class: true
+ override: true
+ sticky: false
+ caption: ''
+ summary: ''
+ description: ''
+ columns:
+ name: name
+ info:
+ name:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ default: '-1'
+ empty_table: false
+ row:
+ type: fields
+ options:
+ inline: { }
+ separator: ''
+ hide_empty: false
+ default_field_elements: true
+ fields:
+ name:
+ table: entity_test_mul_revlog_property_data
+ field: name
+ id: name
+ entity_type: entity_test_mul_revlog
+ entity_field: name
+ plugin_id: field
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: ''
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: string
+ settings: { }
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ revision_created:
+ id: revision_created
+ table: entity_test_mul_revlog_property_data
+ field: revision_created
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision create time'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: timestamp
+ settings:
+ date_format: medium
+ custom_date_format: ''
+ timezone: ''
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_mul_revlog
+ entity_field: revision_created
+ plugin_id: field
+ revision_id:
+ id: revision_id
+ table: entity_test_mul_revlog_property_data
+ field: revision_id
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision ID'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: number_integer
+ settings:
+ thousand_separator: ''
+ prefix_suffix: true
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_mul_revlog
+ entity_field: revision_id
+ plugin_id: field
+ revision_log_message:
+ id: revision_log_message
+ table: entity_test_mul_revlog_property_data
+ field: revision_log_message
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision log message'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: basic_string
+ settings: { }
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_mul_revlog
+ entity_field: revision_log_message
+ plugin_id: field
+ revision_user:
+ id: revision_user
+ table: entity_test_mul_revlog_property_data
+ field: revision_user
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision user'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: target_id
+ type: entity_reference_label
+ settings:
+ link: true
+ group_column: target_id
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_mul_revlog
+ entity_field: revision_user
+ plugin_id: field
+ filters: { }
+ sorts: { }
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments: { }
+ display_extenders: { }
+ cache_metadata:
+ max-age: 0
+ contexts:
+ - 'languages:language_content'
+ - 'languages:language_interface'
+ - url.query_args
+ tags: { }
diff --git a/core/modules/system/tests/fixtures/update/views.view.entity_test_revlog_for_2248983.yml b/core/modules/system/tests/fixtures/update/views.view.entity_test_revlog_for_2248983.yml
new file mode 100644
index 0000000..412972c
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/views.view.entity_test_revlog_for_2248983.yml
@@ -0,0 +1,436 @@
+uuid: 5a8b00d2-67ce-415b-9e7d-6c013bf7f6b8
+langcode: en
+status: true
+dependencies:
+ module:
+ - entity_test_revlog
+id: entity_test_revlog_for_2248983
+label: entity_test_revlog
+module: views
+description: ''
+tag: ''
+base_table: entity_test_revlog
+base_field: id
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 0
+ display_options:
+ access:
+ type: none
+ options: { }
+ cache:
+ type: tag
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ replica: false
+ query_comment: ''
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: mini
+ options:
+ items_per_page: 10
+ offset: 0
+ id: 0
+ total_pages: null
+ expose:
+ items_per_page: false
+ items_per_page_label: 'Items per page'
+ items_per_page_options: '5, 10, 25, 50'
+ items_per_page_options_all: false
+ items_per_page_options_all_label: '- All -'
+ offset: false
+ offset_label: Offset
+ tags:
+ previous: ‹‹
+ next: ››
+ style:
+ type: table
+ options:
+ grouping: { }
+ row_class: ''
+ default_row_class: true
+ override: true
+ sticky: false
+ caption: ''
+ summary: ''
+ description: ''
+ columns:
+ name: name
+ info:
+ name:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ default: '-1'
+ empty_table: false
+ row:
+ type: fields
+ options:
+ inline: { }
+ separator: ''
+ hide_empty: false
+ default_field_elements: true
+ fields:
+ name:
+ id: name
+ table: entity_test_revlog
+ field: name
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: Name
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: string
+ settings:
+ link_to_entity: false
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_revlog
+ entity_field: name
+ plugin_id: field
+ revision_created:
+ id: revision_created
+ table: entity_test_revlog
+ field: revision_created
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision create time'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: timestamp
+ settings:
+ date_format: medium
+ custom_date_format: ''
+ timezone: ''
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_revlog
+ entity_field: revision_created
+ plugin_id: field
+ revision_id:
+ id: revision_id
+ table: entity_test_revlog
+ field: revision_id
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision ID'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: number_integer
+ settings:
+ thousand_separator: ''
+ prefix_suffix: true
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_revlog
+ entity_field: revision_id
+ plugin_id: field
+ revision_log_message:
+ id: revision_log_message
+ table: entity_test_revlog
+ field: revision_log_message
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision log message'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: basic_string
+ settings: { }
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_revlog
+ entity_field: revision_log_message
+ plugin_id: field
+ revision_user:
+ id: revision_user
+ table: entity_test_revlog
+ field: revision_user
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: 'Revision user'
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: target_id
+ type: entity_reference_label
+ settings:
+ link: true
+ group_column: target_id
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ entity_type: entity_test_revlog
+ entity_field: revision_user
+ plugin_id: field
+ filters: { }
+ sorts: { }
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments: { }
+ display_extenders: { }
+ cache_metadata:
+ max-age: 0
+ contexts:
+ - 'languages:language_content'
+ - 'languages:language_interface'
+ - url.query_args
+ tags: { }
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithRevisionLog.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithRevisionLog.php
deleted file mode 100644
index 4f4f4f1..0000000
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithRevisionLog.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-namespace Drupal\entity_test\Entity;
-
-use Drupal\Core\Entity\RevisionableContentEntityBase;
-
-/**
- * Defines the test entity class.
- *
- * @ContentEntityType(
- * id = "entity_test_revlog",
- * label = @Translation("Test entity - revisions log"),
- * handlers = {
- * "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
- * "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
- * "form" = {
- * "default" = "Drupal\entity_test\EntityTestForm",
- * "delete" = "Drupal\entity_test\EntityTestDeleteForm"
- * },
- * "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
- * "translation" = "Drupal\content_translation\ContentTranslationHandler",
- * "views_data" = "Drupal\views\EntityViewsData",
- * "route_provider" = {
- * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
- * },
- * },
- * base_table = "entity_test_revlog",
- * revision_table = "entity_test_revlog_revision",
- * admin_permission = "administer entity_test content",
- * entity_keys = {
- * "id" = "id",
- * "uuid" = "uuid",
- * "revision" = "revision_id",
- * "bundle" = "type",
- * "label" = "name",
- * "langcode" = "langcode",
- * },
- * links = {
- * "canonical" = "/entity_test_revlog/manage/{entity_test_revlog}",
- * "delete-form" = "/entity_test/delete/entity_test_revlog/{entity_test_revlog}",
- * "edit-form" = "/entity_test_revlog/manage/{entity_test_revlog}/edit",
- * "revision" = "/entity_test_revlog/{entity_test_revlog}/revision/{entity_test_revlog_revision}/view",
- * }
- * )
- */
-class EntityTestWithRevisionLog extends RevisionableContentEntityBase {
-
-}
diff --git a/core/modules/system/tests/modules/entity_test_revlog/entity_test_revlog.info.yml b/core/modules/system/tests/modules/entity_test_revlog/entity_test_revlog.info.yml
new file mode 100644
index 0000000..4afba62
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test_revlog/entity_test_revlog.info.yml
@@ -0,0 +1,6 @@
+name: 'Entity test revision log'
+type: module
+description: 'Provides two entity types with revision logging capabilities.'
+package: Testing
+version: VERSION
+core: 8.x
diff --git a/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php
new file mode 100644
index 0000000..5a17b85
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Drupal\entity_test_revlog\Entity;
+
+/**
+ * Defines the test entity class.
+ *
+ * @ContentEntityType(
+ * id = "entity_test_mul_revlog",
+ * label = @Translation("Test entity - data table, revisions log"),
+ * base_table = "entity_test_mul_revlog",
+ * data_table = "entity_test_mul_revlog_field_data",
+ * revision_table = "entity_test_mul_revlog_revision",
+ * revision_data_table = "entity_test_mul_revlog_field_revision",
+ * translatable = TRUE,
+ * entity_keys = {
+ * "id" = "id",
+ * "uuid" = "uuid",
+ * "revision" = "revision_id",
+ * "bundle" = "type",
+ * "label" = "name",
+ * "langcode" = "langcode",
+ * },
+ * revision_metadata_keys = {
+ * "revision_user" = "revision_user",
+ * "revision_created" = "revision_created",
+ * "revision_log_message" = "revision_log_message"
+ * },
+ * )
+ */
+class EntityTestMulWithRevisionLog extends EntityTestWithRevisionLog {
+
+}
diff --git a/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestWithRevisionLog.php b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestWithRevisionLog.php
new file mode 100644
index 0000000..8d9b4d1
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestWithRevisionLog.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Drupal\entity_test_revlog\Entity;
+
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Entity\RevisionableContentEntityBase;
+use Drupal\Core\Field\BaseFieldDefinition;
+
+/**
+ * Defines the test entity class.
+ *
+ * @ContentEntityType(
+ * id = "entity_test_revlog",
+ * label = @Translation("Test entity - revisions log"),
+ * base_table = "entity_test_revlog",
+ * revision_table = "entity_test_revlog_revision",
+ * entity_keys = {
+ * "id" = "id",
+ * "uuid" = "uuid",
+ * "revision" = "revision_id",
+ * "bundle" = "type",
+ * "label" = "name",
+ * "langcode" = "langcode",
+ * },
+ * revision_metadata_keys = {
+ * "revision_user" = "revision_user",
+ * "revision_created" = "revision_created",
+ * "revision_log_message" = "revision_log_message"
+ * },
+ * )
+ */
+class EntityTestWithRevisionLog extends RevisionableContentEntityBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
+ $fields = parent::baseFieldDefinitions($entity_type);
+
+ $fields['name'] = BaseFieldDefinition::create('string')
+ ->setLabel(t('Name'))
+ ->setDescription(t('The name of the test entity.'))
+ ->setTranslatable(TRUE)
+ ->setRevisionable(TRUE)
+ ->setSetting('max_length', 32)
+ ->setDisplayOptions('view', array(
+ 'label' => 'hidden',
+ 'type' => 'string',
+ 'weight' => -5,
+ ))
+ ->setDisplayOptions('form', array(
+ 'type' => 'string_textfield',
+ 'weight' => -5,
+ ));
+
+ return $fields;
+ }
+
+}
diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php
index 1e9fac1..f75badb 100644
--- a/core/modules/views/src/Entity/View.php
+++ b/core/modules/views/src/Entity/View.php
@@ -5,7 +5,9 @@ namespace Drupal\views\Entity;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\views\Views;
use Drupal\views\ViewEntityInterface;
@@ -290,10 +292,13 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
+ $displays = $this->get('display');
+
+ $this->fixTableNames($displays);
+
// Sort the displays.
- $display = $this->get('display');
- ksort($display);
- $this->set('display', array('default' => $display['default']) + $display);
+ ksort($displays);
+ $this->set('display', ['default' => $displays['default']] + $displays);
// @todo Check whether isSyncing is needed.
if (!$this->isSyncing()) {
@@ -302,6 +307,45 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
}
/**
+ * Fixes table names for revision metadata fields of revisionable entities.
+ *
+ * Views for revisionable entity types using revision metadata fields might
+ * be using the wrong table to retrieve the fields after system_update_8300
+ * has moved them correctly to the revision table. This method updates the
+ * views to use the correct tables.
+ *
+ * @param array &$displays
+ * An array containing display handlers of a view.
+ *
+ * @deprecated in Drupal 8.3.0, will be removed in Drupal 9.0.0.
+ */
+ private function fixTableNames(array &$displays) {
+ // Fix wrong table names for entity revision metadata fields.
+ foreach ($displays as $display => $display_data) {
+ if (isset($display_data['display_options']['fields'])) {
+ foreach ($display_data['display_options']['fields'] as $property_name => $property_data) {
+ if (isset($property_data['entity_type']) && isset($property_data['field']) && isset($property_data['table'])) {
+ $entity_type = $this->entityTypeManager()->getDefinition($property_data['entity_type']);
+ // We need to update the table name only for revisionable entity
+ // types, otherwise the view is already using the correct table.
+ if (($entity_type instanceof ContentEntityTypeInterface) && is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) && $entity_type->isRevisionable()) {
+ $revision_metadata_fields = $entity_type->getRevisionMetadataKeys();
+ // @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage::initTableLayout()
+ $revision_table = $entity_type->getRevisionTable() ?: $entity_type->id() . '_revision';
+
+ // Check if this is a revision metadata field and if it uses the
+ // wrong table.
+ if (in_array($property_data['field'], $revision_metadata_fields) && $property_data['table'] != $revision_table) {
+ $displays[$display]['display_options']['fields'][$property_name]['table'] = $revision_table;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Fills in the cache metadata of this view.
*
* Cache metadata is set per view and per display, and ends up being stored in
diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
index 1b163e2..276fc5c 100644
--- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
@@ -9,7 +9,6 @@ namespace Drupal\Tests\views\Unit;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\ContentEntityType;
-use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Sql\DefaultTableMapping;
use Drupal\Core\Field\BaseFieldDefinition;
@@ -1087,7 +1086,7 @@ class TestEntityViewsData extends EntityViewsData {
}
-class TestEntityType extends EntityType {
+class TestEntityType extends ContentEntityType {
/**
* Sets a specific entity key.
diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php
index a4da940..b9e4c68 100644
--- a/core/modules/views/views.post_update.php
+++ b/core/modules/views/views.post_update.php
@@ -239,3 +239,24 @@ function views_post_update_boolean_filter_values() {
/**
* @} End of "addtogroup updates-8.2.x".
*/
+
+/**
+ * @addtogroup updates-8.3.x
+ * @{
+ */
+
+/**
+ * Fix table names for revision metadata fields.
+ */
+function views_post_update_revision_metadata_fields() {
+ // The table names are fixed automatically in
+ // \Drupal\views\Entity\View::preSave(), so we just need to re-save all views.
+ $views = View::loadMultiple();
+ array_walk($views, function(View $view) {
+ $view->save();
+ });
+}
+
+/**
+ * @} End of "addtogroup updates-8.3.x".
+ */
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php
index 1fd873c..b78a588 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php
@@ -2,7 +2,7 @@
namespace Drupal\KernelTests\Core\Entity;
-use Drupal\entity_test\Entity\EntityTestWithRevisionLog;
+use Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
@@ -15,7 +15,7 @@ class RevisionableContentEntityBaseTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
- public static $modules = ['entity_test', 'system', 'user'];
+ public static $modules = ['entity_test_revlog', 'system', 'user'];
/**
* {@inheritdoc}
@@ -31,7 +31,7 @@ class RevisionableContentEntityBaseTest extends KernelTestBase {
public function testRevisionableContentEntity() {
$user = User::create(['name' => 'test name']);
$user->save();
- /** @var \Drupal\entity_test\Entity\EntityTestWithRevisionLog $entity */
+ /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
$entity = EntityTestWithRevisionLog::create([
'type' => 'entity_test_revlog',
]);
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
index 5d56929..f552bfe 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
@@ -534,6 +534,9 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('bundle', $entity_keys['bundle']),
array('revision', $entity_keys['revision']),
)));
+ $this->entityType->expects($this->any())
+ ->method('getRevisionMetadataKeys')
+ ->will($this->returnValue([]));
$this->setUpEntityStorage();
@@ -574,13 +577,13 @@ class SqlContentEntityStorageTest extends UnitTestCase {
// PHPUnit does not allow for multiple data providers.
$test_cases = array(
array(),
- array('revision_timestamp'),
- array('revision_uid'),
- array('revision_log'),
- array('revision_timestamp', 'revision_uid'),
- array('revision_timestamp', 'revision_log'),
- array('revision_uid', 'revision_log'),
- array('revision_timestamp', 'revision_uid', 'revision_log'),
+ array('revision_created' => 'revision_timestamp'),
+ array('revision_user' => 'revision_uid'),
+ array('revision_log_message' => 'revision_log'),
+ array('revision_created' => 'revision_timestamp', 'revision_user' => 'revision_uid'),
+ array('revision_created' => 'revision_timestamp', 'revision_log_message' => 'revision_log'),
+ array('revision_user' => 'revision_uid', 'revision_log_message' => 'revision_log'),
+ array('revision_created' => 'revision_timestamp', 'revision_user' => 'revision_uid', 'revision_log_message' => 'revision_log'),
);
foreach ($test_cases as $revision_metadata_field_names) {
$this->setUp();
@@ -591,7 +594,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$revisionable_field_names = array('description', 'owner');
$field_names = array_merge($field_names, $revisionable_field_names);
- $this->fieldDefinitions += $this->mockFieldDefinitions(array_merge($revisionable_field_names, $revision_metadata_field_names), array('isRevisionable' => TRUE));
+ $this->fieldDefinitions += $this->mockFieldDefinitions(array_merge($revisionable_field_names, array_values($revision_metadata_field_names)), array('isRevisionable' => TRUE));
$this->entityType->expects($this->exactly(2))
->method('isRevisionable')
@@ -605,6 +608,10 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('revision', $entity_keys['revision']),
)));
+ $this->entityType->expects($this->any())
+ ->method('getRevisionMetadataKeys')
+ ->will($this->returnValue($revision_metadata_field_names));
+
$this->setUpEntityStorage();
$mapping = $this->entityStorage->getTableMapping();
@@ -616,7 +623,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$expected = array_merge(
array($entity_keys['id'], $entity_keys['revision']),
$revisionable_field_names,
- $revision_metadata_field_names
+ array_values($revision_metadata_field_names)
);
$this->assertEquals($expected, $mapping->getFieldNames('entity_test_revision'));
@@ -761,6 +768,11 @@ class SqlContentEntityStorageTest extends UnitTestCase {
'uuid' => $entity_keys['uuid'],
'langcode' => 'langcode',
);
+ $revision_metadata_keys = array(
+ 'revision_created' => 'revision_timestamp',
+ 'revision_user' => 'revision_uid',
+ 'revision_log_message' => 'revision_log'
+ );
$this->entityType->expects($this->atLeastOnce())
->method('isRevisionable')
@@ -780,6 +792,9 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('revision', $entity_keys['revision']),
array('langcode', $entity_keys['langcode']),
)));
+ $this->entityType->expects($this->any())
+ ->method('getRevisionMetadataKeys')
+ ->will($this->returnValue($revision_metadata_keys));
$this->setUpEntityStorage();
@@ -810,6 +825,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$entity_keys['revision'],
$entity_keys['langcode'],
)));
+ $expected = array_merge($expected, array_values($revision_metadata_keys));
$actual = $mapping->getFieldNames('entity_test_revision');
$this->assertEquals($expected, $actual);
// The UUID is not stored on the data table.
@@ -865,13 +881,13 @@ class SqlContentEntityStorageTest extends UnitTestCase {
// PHPUnit does not allow for multiple data providers.
$test_cases = array(
array(),
- array('revision_timestamp'),
- array('revision_uid'),
- array('revision_log'),
- array('revision_timestamp', 'revision_uid'),
- array('revision_timestamp', 'revision_log'),
- array('revision_uid', 'revision_log'),
- array('revision_timestamp', 'revision_uid', 'revision_log'),
+ array('revision_created' => 'revision_timestamp'),
+ array('revision_user' => 'revision_uid'),
+ array('revision_log_message' => 'revision_log'),
+ array('revision_created' => 'revision_timestamp', 'revision_user' => 'revision_uid'),
+ array('revision_created' => 'revision_timestamp', 'revision_log_message' => 'revision_log'),
+ array('revision_user' => 'revision_uid', 'revision_log_message' => 'revision_log'),
+ array('revision_created' => 'revision_timestamp', 'revision_user' => 'revision_uid', 'revision_log_message' => 'revision_log'),
);
foreach ($test_cases as $revision_metadata_field_names) {
$this->setUp();
@@ -881,7 +897,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$this->fieldDefinitions = $this->mockFieldDefinitions($field_names);
$revisionable_field_names = array('description', 'owner');
- $this->fieldDefinitions += $this->mockFieldDefinitions(array_merge($revisionable_field_names, $revision_metadata_field_names), array('isRevisionable' => TRUE));
+ $this->fieldDefinitions += $this->mockFieldDefinitions(array_merge($revisionable_field_names, array_values($revision_metadata_field_names)), array('isRevisionable' => TRUE));
$this->entityType->expects($this->atLeastOnce())
->method('isRevisionable')
@@ -901,6 +917,9 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('revision', $entity_keys['revision']),
array('langcode', $entity_keys['langcode']),
)));
+ $this->entityType->expects($this->any())
+ ->method('getRevisionMetadataKeys')
+ ->will($this->returnValue($revision_metadata_field_names));
$this->setUpEntityStorage();
@@ -938,7 +957,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
$entity_keys['id'],
$entity_keys['revision'],
$entity_keys['langcode'],
- )), $revision_metadata_field_names);
+ )), array_values($revision_metadata_field_names));
$actual = $mapping->getFieldNames('entity_test_revision');
$this->assertEquals($expected, $actual);
// The UUID is not stored on the data table.
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index 25d498e..e3d3c77 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -750,6 +750,16 @@ $settings['file_scan_ignore_directories'] = [
];
/**
+ * The default number of entities to update in a batch process.
+ *
+ * This is used by update and post-update functions that need to go through and
+ * change all the entities on a site, so it is useful to increase this number
+ * if your hosting configuration (i.e. RAM allocation, CPU speed) allows for a
+ * larger number of entities to be processed in a single batch run.
+ */
+$settings['entity_update_batch_size'] = 50;
+
+/**
* Load local development override configuration, if available.
*
* Use settings.local.php to override variables on secondary (staging,