diff --git a/core/lib/Drupal/Core/Entity/EntityFieldValueUpdater.php b/core/lib/Drupal/Core/Entity/EntityFieldValueUpdater.php index e69de29..2abb160 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldValueUpdater.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldValueUpdater.php @@ -0,0 +1,32 @@ +entityType = $entity_type; + } + + public function updateRevisionUuid(array $revisions, $count = 100) { + $i = 0; + while (!empty($revisions) && $i < $count) { + $i++; + $revision_id = current(array_keys($revisions)); + \Drupal::database() + ->update($this->entityType->getRevisionTable()) + ->fields([$this->entityType->getKey('revision_uuid') => \Drupal::service('uuid')->generate()]) + ->condition($this->entityType->getKey('revision'), $revision_id) + ->execute(); + unset($revisions[$revision_id]); + } + return $revisions; + } +} diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index e259f48..459dfc0 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -5,6 +5,7 @@ * Install, update and uninstall functions for the block_content module. */ +use Drupal\Core\Entity\EntityFieldValueUpdater; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -72,4 +73,16 @@ function block_content_update_8300() { ->setRevisionable(TRUE) ->setReadOnly(TRUE); \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('revision_uuid', 'block_content', 'block_content', $revision_uuid); + + $storage = \Drupal::entityTypeManager()->getStorage('block_content'); + $revisions = $storage->getQuery() + ->allRevisions() + ->execute(); + if (count($revisions) < 100) { + $entity_field_value_updater = new EntityFieldValueUpdater($storage->getEntityType()); + $entity_field_value_updater->updateRevisionUuid($revisions); + } + else { + \Drupal::state()->set('block_content:revision_uuid_update', $revisions); + } } diff --git a/core/modules/block_content/block_content.module b/core/modules/block_content/block_content.module index e0b5729..d51033d 100644 --- a/core/modules/block_content/block_content.module +++ b/core/modules/block_content/block_content.module @@ -5,6 +5,7 @@ * Allows the creation of custom blocks through the user interface. */ +use Drupal\Core\Entity\EntityFieldValueUpdater; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -105,3 +106,15 @@ function block_content_add_body_field($block_type_id, $label = 'Body') { return $field; } + +/** + * Implements hook_cron(). + */ +function block_content_cron() { + $revisions = \Drupal::state()->get('block_content:revision_uuid_update'); + if (!empty($revisions)) { + $entity_field_value_updater = new EntityFieldValueUpdater(\Drupal::entityTypeManager()->getStorage('block_content')->getEntityType()); + $remaining_revisions = $entity_field_value_updater->updateRevisionUuid($revisions); + \Drupal::state()->set('node:revision_uuid_update', $remaining_revisions); + } +} diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 6e05700..373b06f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Database\Database; +use Drupal\Core\Entity\EntityFieldValueUpdater; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\user\RoleInterface; @@ -245,4 +246,16 @@ function node_update_8301() { ->setRevisionable(TRUE) ->setReadOnly(TRUE); \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('revision_uuid', 'node', 'node', $revision_uuid); + + $storage = \Drupal::entityTypeManager()->getStorage('node'); + $revisions = $storage->getQuery() + ->allRevisions() + ->execute(); + if (count($revisions) < 100) { + $entity_field_value_updater = new EntityFieldValueUpdater($storage->getEntityType()); + $entity_field_value_updater->updateRevisionUuid($revisions); + } + else { + \Drupal::state()->set('node:revision_uuid_update', $revisions); + } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 5c67317..21eb4de 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -15,6 +15,7 @@ use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\StatementInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; +use Drupal\Core\Entity\EntityFieldValueUpdater; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; @@ -637,6 +638,13 @@ function node_cron() { \Drupal::state()->set('node.min_max_update_time', $array); } } + + $revisions = \Drupal::state()->get('node:revision_uuid_update'); + if (!empty($revisions)) { + $entity_field_value_updater = new EntityFieldValueUpdater(\Drupal::entityTypeManager()->getStorage('node')->getEntityType()); + $remaining_revisions = $entity_field_value_updater->updateRevisionUuid($revisions); + \Drupal::state()->set('node:revision_uuid_update', $remaining_revisions); + } } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php index d7651c4..45b2f04 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php @@ -97,6 +97,9 @@ protected function getExpectedNormalizedEntity() { 'vid' => [ ['value' => 1], ], + 'revision_uuid' => [ + ['value' => $this->entity->getRevisionUuid()], + ], 'langcode' => [ [ 'value' => 'en',