diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index 459dfc0..363675a 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -5,7 +5,6 @@ * 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; @@ -74,15 +73,8 @@ function block_content_update_8300() { ->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); - } + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + $revision_uuid_update[] = 'block_content'; + $state->set('revision_uuid_update', $revision_uuid_update); } diff --git a/core/modules/block_content/block_content.module b/core/modules/block_content/block_content.module index d51033d..e0b5729 100644 --- a/core/modules/block_content/block_content.module +++ b/core/modules/block_content/block_content.module @@ -5,7 +5,6 @@ * 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; @@ -106,15 +105,3 @@ 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/block_content/src/Tests/BlockContentUpdateTest.php b/core/modules/block_content/src/Tests/BlockContentUpdateTest.php index 5908fcb..9cf871b 100644 --- a/core/modules/block_content/src/Tests/BlockContentUpdateTest.php +++ b/core/modules/block_content/src/Tests/BlockContentUpdateTest.php @@ -28,6 +28,8 @@ protected function setDatabaseDumpFiles() { */ public function testRevisionUuidUpdate() { $this->runUpdates(); + sleep(5); + $this->cronRun(); $block_contents = \Drupal::entityTypeManager()->getStorage('block_content')->loadMultiple(); foreach ($block_contents as $block_content) { diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 321e583..661831f 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -264,17 +264,11 @@ function node_update_8302() { ->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); - } + + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + $revision_uuid_update[] = 'node'; + $state->set('revision_uuid_update', $revision_uuid_update); } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 9c2f165..5c86a13 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -15,7 +15,6 @@ 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; @@ -638,13 +637,6 @@ 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/node/src/Tests/Update/NodeUpdateTest.php b/core/modules/node/src/Tests/Update/NodeUpdateTest.php index ac78326..e1d8964 100644 --- a/core/modules/node/src/Tests/Update/NodeUpdateTest.php +++ b/core/modules/node/src/Tests/Update/NodeUpdateTest.php @@ -46,6 +46,7 @@ public function testPublishedEntityKey() { */ public function testRevisionUuidUpdate() { $this->runUpdates(); + $this->cronRun(); $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple(); foreach ($nodes as $node) { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 3c858f9..11d22a1 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1289,6 +1289,36 @@ function system_cron() { // Clean up PHP storage. PhpStorageFactory::get('container')->garbageCollection(); PhpStorageFactory::get('service_container')->garbageCollection(); + + // Update revision_uuid field values + $state = \Drupal::state(); + $revision_uuid_update = $state->get('revision_uuid_update'); + foreach ($revision_uuid_update as $entity_type_id) { + $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); + $query = \Drupal::database() + ->select($entity_type->getRevisionTable(), 'revision_table') + ->fields('revision_table', [$entity_type->getKey('revision')]) + ->where('%revision = %revision_uuid', [ + '%revision' => $entity_type->getKey('revision'), + '%revision_uuid' => $entity_type->getKey('revision_uuid') + ]) + ->range(0, 100); + $revisions = $query->execute()->fetchCol(); + if ($revisions) { + foreach ($revisions as $revision) { + \Drupal::database() + ->update($this->entityType->getRevisionTable()) + ->fields([$this->entityType->getKey('revision_uuid') => \Drupal::service('uuid')->generate()]) + ->condition($this->entityType->getKey('revision'), $revision) + ->execute(); + } + } + else { + unset($revision_uuid_update[$entity_type->id()]); + $state->set('node:revision_uuid_update', $revision_uuid_update); + } + } + } /**