diff --git a/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php b/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php index 209473b..8523404 100644 --- a/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php +++ b/core/modules/system/src/Tests/Entity/Update/LatestRevisionIdUpdateTest.php @@ -70,7 +70,10 @@ public function testSystemUpdate8401() { // A node with translated content and a forward revision. $node = Node::load(3); $this->assertEqual(8, $node->getLatestRevisionId()); - $this->assertEqual(8, $node->getTranslation('de')->getLatestRevisionId()); + $translated_node = $node->getTranslation('de'); + $this->assertEqual(8, $translated_node->getLatestRevisionId()); + $this->assertEqual(8, $translated_node->getLatestTranslationAffectedRevisionId()); + $this->assertEqual(7, $node->getLatestTranslationAffectedRevisionId()); // Load an entity of a different type with a forward revision. $block_content = BlockContent::load(1); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index c62474b..8a17ff6 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1941,6 +1941,12 @@ function system_update_8401(&$sandbox) { ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); + $latest_revision_translation_affected_field = BaseFieldDefinition::create('integer') + ->setLabel(new TranslatableMarkup('Latest Revision Translation Affected')) + ->setReadOnly(TRUE) + ->setTranslatable(TRUE) + ->setSetting('unsigned', TRUE); + // Initialise the sandbox with a list of entity type IDs we need to update. if (!isset($sandbox['current'])) { $sandbox['current'] = 0; @@ -1974,6 +1980,10 @@ function system_update_8401(&$sandbox) { // Install the latest_revision field before updating any entities. $entity_definition_update_manager->installFieldStorageDefinition('latest_revision', $entity_type->id(), $entity_type->getProvider(), $latest_revision_field); + + if ($entity_type->isTranslatable()) { + $entity_definition_update_manager->installFieldStorageDefinition('latest_revision_translation_affected', $entity_type->id(), $entity_type->getProvider(), $latest_revision_translation_affected_field); + } } $entities = \Drupal::entityQuery($entity_type->id()) @@ -1992,6 +2002,33 @@ function system_update_8401(&$sandbox) { ->condition($entity_type->getKey('id'), $entity_id) ->fields(['latest_revision' => $latest_revision_id]) ->execute(); + + + if ($entity_type->isTranslatable()) { + // @todo, why is ->getRevisionDataTable() null? + $revision_data_table = $entity_type->id() . '_field_revision'; + $latest_revision_translation_affected_query = \Drupal::database()->select($revision_data_table, 'r'); + $latest_revision_translation_affected_query->fields('r', [ + $entity_type->getKey('langcode'), + // @todo, what do we do with entities without the field? + 'revision_translation_affected', + ]); + $latest_revision_translation_affected_query->condition($entity_type->getKey('id'), $entity_id); + $latest_revision_translation_affected_query->groupBy($entity_type->getKey('langcode')); + $latest_revision_translation_affected_query->condition('revision_translation_affected', '1'); + $latest_revision_translation_affected_query->addExpression('max(' . $entity_type->getKey('revision') . ')', 'latest_revision_translation_affected'); + + $foo = (string) $latest_revision_translation_affected_query; + + $results = $latest_revision_translation_affected_query->execute(); + foreach ($results as $latest_revision_translation_affected_data) { + \Drupal::database()->update($entity_type->getDataTable()) + ->condition($entity_type->getKey('id'), $entity_id) + ->condition($entity_type->getKey('langcode'), $latest_revision_translation_affected_data->{$entity_type->getKey('langcode')}) + ->fields(['latest_revision_translation_affected' => $latest_revision_translation_affected_data->latest_revision_translation_affected]) + ->execute(); + } + } } // Keep track of how many entities have been updated and if the batch is diff --git a/core/modules/system/tests/fixtures/update/drupal-8.latest-revision-entities-2784201.php b/core/modules/system/tests/fixtures/update/drupal-8.latest-revision-entities-2784201.php index 948e629..6821661 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.latest-revision-entities-2784201.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.latest-revision-entities-2784201.php @@ -166,7 +166,7 @@ 'changed' => '1490867245', 'promote' => '1', 'sticky' => '0', - 'revision_translation_affected' => NULL, + 'revision_translation_affected' => '1', 'default_langcode' => '0', )) ->values(array(