Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301255

Fields tables are not updated correctly when setting an existing revision as the new default one

$
0
0

Problem/Motivation

I encounter a problem with the revision system when I try to set an existing revision as the new default one.

The entity is correctly updated (in node_field_data in this case) but fields tables (node__body for example) are not updated and remains at their previous revision ID.

This problem comes from this code snippet in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php :

// When updating an existing revision, keep the existing records if the
// field values did not change.
if (!$entity->isNewRevision() && $original && !$this->hasFieldValueChanged($field_definition, $entity, $original)) {
  continue;
}

In this case, the revision is not a new one (as it has been created previously as an unpublished revision) and the field values are not found as changed because $original contains the revision we are saving (and not the previous active revision).

So the condition is considere TRUE and the loop trigger the "continue" action and do not update the field table.

Steps to reproduce

  1. Create a node and publish it to have a revision A
  2. Edit the node fields and create so a new revision B but do not publish it
  3. Try to make the new revision B the default one programmatically by using $node->isDefaultRevision(TRUE) and $node->setPublished()
  4. See that the new revision B is correctly set as the default one, but the fields values are the one of the initial revision A.

Proposed resolution

I think the condition needs to be adapted to considere the case of an existing revision becoming the new default one.
So we have to retrieve the current revision id, compare it to the default revision we are saving and allow an update of fields dedicated tables if the revision is the new default one.

The patch attached check this new condition before to skip fields tables update.


Viewing all articles
Browse latest Browse all 301255

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>