Implementations of hook_node_update should check the "isDefaultRevision" property

Created on 8 April 2012, over 13 years ago
Updated 14 January 2025, 7 months ago

For Drupal 8 to support "forward revisions" it must declare during node_save whether the given node object is meant to go in the node table or not. Agentrickard has started a patch to this end at #218755-106: Support revisions in different states

The addition of the is_live property means that many modules implementing hook_node_update() will have to check that the given revision is going live.

For instance, the path module should not change the alias for node/123 if the revision of 123 being saved is not going to the node table.

This patch is a start. There are UI implications to this change. With this patch, data entered in the URL alias field is discarded if the revision isn't going live.

Finally I think this patch will fail testing as it does not include the is_live property from #218755-106: Support revisions in different states and some tests will have to be modified/added to deal with is_live anyway.

📌 Task
Status

Needs work

Version

11.0 🔥

Component

node system

Created by

🇺🇸United States stevector Minneapolis, MN

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇭Switzerland berdir Switzerland

    I think the only bit here that's not addressed yet is search, which is in \Drupal\node\Entity\Node::postSave() now, there are also node_comment hooks that update the search index.

  • 🇨🇦Canada danrod Ottawa

    I attached a patch that checks for isDefaultRevision() being set to TRUE before running node_reindex_node_search and same situation for commentInsert or commentUpdate and or commentDelete at /core/modules/node/src/Hook/NodeHooks1.php

    I'm starting to do some Core contribution so bear with me when reviewing.

  • 🇨🇭Switzerland berdir Switzerland

    All contributions must be merge requests.

  • First commit to issue fork.
  • 🇮🇳India Sivaji_Ganesh_Jojodae Chennai

    Created MR to reflect the above comments.

  • Pipeline finished with Failed
    6 months ago
    Total: 421s
    #438617
  • Pipeline finished with Failed
    6 months ago
    Total: 389s
    #438662
  • 🇨🇦Canada danrod Ottawa

    Thanks @berdir , good to know, I'll do that next time.

  • 🇺🇸United States smustgrave

    Have not reviewed but issue summary appears incomplete

  • 🇨🇦Canada danrod Ottawa

    I improved the issue summary, hope it makes more sense.

  • Pipeline finished with Failed
    6 months ago
    Total: 404s
    #439934
  • Pipeline finished with Success
    6 months ago
    Total: 544s
    #440419
  • 🇺🇸United States smustgrave

    Left some comments on the MR.

  • Pipeline finished with Failed
    5 months ago
    Total: 507s
    #450711
  • Pipeline finished with Failed
    5 months ago
    Total: 175s
    #450741
  • Pipeline finished with Failed
    5 months ago
    Total: 454s
    #451207
  • Pipeline finished with Failed
    5 months ago
    Total: 629s
    #451386
  • 🇨🇦Canada danrod Ottawa

    I documented the $comment parameter, added some more information and created a simple $this->assertTrue() in the testDeterminingChanges() test method (file core/modules/node/tests/src/Functional/NodeSaveTest.php) to test if the node that was updated is the default revision, and prints an informative message.

    It seems like a pretty obvious validation but in the real scenario that is what is being check at ./src/Entity/Node::postSave() before updating the node access table and reindex the search table.

    I'm open to any suggestions on this.

  • 🇺🇸United States smustgrave

    Leaving tests tag as the test-only pipeline is passing when I'd expect it to fail.

  • Pipeline finished with Failed
    5 months ago
    Total: 648s
    #468611
  • Pipeline finished with Failed
    5 months ago
    Total: 125s
    #468890
  • Pipeline finished with Failed
    5 months ago
    Total: 103s
    #468902
  • Pipeline finished with Failed
    5 months ago
    Total: 637s
    #468913
  • 🇨🇦Canada danrod Ottawa

    I refactored the test in a new function,testNodeDefaultRevision(), which checks that previous revisions of the node are not reindexed by looking at the index tables.

    https://git.drupalcode.org/project/drupal/-/merge_requests/11353

    The test-only pipeline is not passing this time

    https://git.drupalcode.org/issue/drupal-1522154/-/jobs/4911642

  • Pipeline finished with Running
    5 months ago
    #469247
  • First commit to issue fork.
  • Pipeline finished with Failed
    4 months ago
    Total: 421s
    #472697
  • 🇦🇺Australia acbramley

    Rebased and slightly tidied up the test.

  • Pipeline finished with Success
    4 months ago
    Total: 24658s
    #472704
  • 🇺🇸United States smustgrave

    Ran testonly feature

    1) Drupal\Tests\node\Functional\NodeSaveTest::testNodeReindexDefaultRevision
    Failed asserting that actual size 1 matches expected size 0.
    /builds/issue/drupal-1522154/core/modules/node/tests/src/Functional/NodeSaveTest.php:245
    FAILURES!
    Tests: 5, Assertions: 52, Failures: 1.
    

    Shows the coverage

    Summary appears to be complete and matches the solution.

    Believe all feedback has also been addressed.

  • 🇬🇧United Kingdom catch

    Couple of comments on the MR.

  • Pipeline finished with Success
    4 months ago
    Total: 483s
    #490708
  • Status changed to RTBC 3 months ago
  • 🇺🇸United States smustgrave

    Feedback appears to be addressed.

  • 🇳🇿New Zealand quietone

    @danrod, thanks for the issue summary update.

    Everything appears to be in order here.

  • Pipeline finished with Success
    2 months ago
    Total: 1255s
    #525667
  • 🇦🇺Australia acbramley

    Rebased and made some slight tweaks to the test so we don't need to install search module for every other test case in NodeSaveTest

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Credits

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Couple of questions on the MR, keeping at RTBC for now

    One is an obvious typo that I'll self apply

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    @berdir flagged in #22

    there are also node_comment hooks that update the search index

    They are as follows:

    1. \Drupal\node\Hook\NodeHooks1::commentInsert
    2. \Drupal\node\Hook\NodeHooks1::commentUpdate
    3. \Drupal\node\Hook\NodeHooks1::commentDelete

    But comments only reference a node by entity-id, not entity and revision ID, so in that scenario I think we're always going to have the default revision

    Setting back to needs review for someone to confirm my thinking on that

  • Pipeline finished with Success
    about 2 months ago
    Total: 678s
    #536575
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs work about 1 month ago
  • 🇬🇧United Kingdom catch

    They are as follows:

    \Drupal\node\Hook\NodeHooks1::commentInsert
    \Drupal\node\Hook\NodeHooks1::commentUpdate
    \Drupal\node\Hook\NodeHooks1::commentDelete
    But comments only reference a node by entity-id, not entity and revision ID, so in that scenario I think we're always going to have the default revision

    I think there are at least theoretical situations where comments are added to forward revisions on sites using content moderation or workspaces. Not sure what the default behaviour is, but a site could certainly be set up to do that - like a special comment field for moderation discussion etc.

  • 🇦🇺Australia acbramley

    Re #56 yeah we reverted the comment changes since you asked back in https://git.drupalcode.org/project/drupal/-/merge_requests/11353#note_51...

    But after manually testing, you can indeed comment on a forward revision when CM is enabled. However, as per #54, comments are added by entity id, not revision id, so the comment appears on the published version.

    I can't think of a world where this mix of modules and edge cases is actually useful (reindexing a node in core's search when a comment is added to a non-default revision, etc) but I also don't feel like this issue is particularly useful either. I would be happy to save time for everyone and close as a won't fix.

  • 🇬🇧United Kingdom catch

    I had absolutely no memory of the MR comment referenced in #57. I think it's technically right to leave the comment behaviour as-is then, even if the use case is weird, it's very unlikely to happen, but also if the comments are added and visible on the default revision, then they might as well update the search index too.

    The actual change in the MR seems right so we could just go ahead with that?

  • Pipeline finished with Failed
    about 1 month ago
    Total: 322s
    #553004
  • 🇨🇦Canada danrod Ottawa

    I've moved this to "Needs Review" just in case you decide to go ahead with the MR.

  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇦🇺Australia acbramley

    The solution was updating outdated (and deprecated) code. I've rebased and squashed the MR with the new fix.

  • Pipeline finished with Success
    about 1 month ago
    Total: 1783s
    #554533
Production build 0.71.5 2024