Implementations of hook_node_update should check the "isDefaultRevision" property

Created on 8 April 2012, about 13 years ago
Updated 14 January 2025, 6 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
    4 months ago
    Total: 421s
    #438617
  • Pipeline finished with Failed
    4 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
    4 months ago
    Total: 404s
    #439934
  • Pipeline finished with Success
    4 months ago
    Total: 544s
    #440419
  • 🇺🇸United States smustgrave

    Left some comments on the MR.

  • Pipeline finished with Failed
    4 months ago
    Total: 507s
    #450711
  • Pipeline finished with Failed
    4 months ago
    Total: 175s
    #450741
  • Pipeline finished with Failed
    4 months ago
    Total: 454s
    #451207
  • Pipeline finished with Failed
    4 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
    3 months ago
    Total: 648s
    #468611
  • Pipeline finished with Failed
    3 months ago
    Total: 125s
    #468890
  • Pipeline finished with Failed
    3 months ago
    Total: 103s
    #468902
  • Pipeline finished with Failed
    3 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
    3 months ago
    #469247
  • First commit to issue fork.
  • Pipeline finished with Failed
    3 months ago
    Total: 421s
    #472697
  • 🇦🇺Australia acbramley

    Rebased and slightly tidied up the test.

  • Pipeline finished with Success
    3 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
    2 months ago
    Total: 483s
    #490708
  • Status changed to RTBC about 2 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
    17 days 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
    4 days ago
    Total: 678s
    #536575
Production build 0.71.5 2024