Problem/Motivation

Initial issue text:

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.

Current situation:

The idea is not to save URL aliases or execute certain procedures if the node being processed is not the default revision, previous patches (mentioned above) have already fixed some of these cases, but as mentioned below by berdir, 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. This MR addresses these cases

Steps to reproduce

- You can use drush eval, load a previous revision of the node:

$node = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($revision_id);

and then try to run

node_reindex_node_search($node->id())

This shouldn't run because this is allowing an old version of the node to be re-indexed.

Proposed resolution

Check isDefaultRevision before calling reindex in NodeSearchHooks::nodeUpdate

Remaining tasks

Review

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-1522154

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

stevector’s picture

Status: Active » Needs review
StatusFileSize
new3.99 KB

Status: Needs review » Needs work

The last submitted patch, is_live-1522154-1.patch, failed testing.

gábor hojtsy’s picture

Title: Implementations of hook_node_update should check the "is_live" property » Implementations of hook_node_update should check the "isDefaultRevision" property

Retitled for the current implementation.

hass’s picture

I really need to know if something goes live in hook_node_update(). Otherwise I cannot run code in linkchecker only if the node get's published. I already have troubles with D7 workbench moderation now. Please let us solve this finally for D8.

stevector’s picture

Thanks for bumping this hass. I forgot about this patch. It still needs a reroll. For the purposes of linkchecker in D8 you can check the isDefaultRevision property. This patch is to make sure the rest of core is checking that property too.

stevector’s picture

Status: Needs work » Needs review
StatusFileSize
new2.52 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 6: isDefaultRevision-check-in-hook-node-update-1522154-6.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berdir’s picture

Issue summary: View changes
Issue tags: +Novice

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.

danrod’s picture

StatusFileSize
new2.69 KB

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 for the first time so bear with me when reviewing.

danrod’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

All contributions must be merge requests.

sivaji_ganesh_jojodae made their first commit to this issue’s fork.

sivaji_ganesh_jojodae’s picture

Status: Needs work » Needs review

Created MR to reflect the above comments.

danrod’s picture

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

And @sivaji_ganesh_jojodae thanks for putting my changes in the MR, it looks accurate.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Have not reviewed but issue summary appears incomplete

danrod’s picture

Issue summary: View changes

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

danrod’s picture

Status: Needs work » Needs review
Issue tags: -Needs issue summary update
danrod’s picture

Issue summary: View changes
danrod’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Novice +Needs tests

Left some comments on the MR.

danrod’s picture

Assigned: Unassigned » danrod
danrod’s picture

Assigned: danrod » Unassigned
danrod’s picture

Assigned: Unassigned » danrod
danrod’s picture

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 checked at ./src/Entity/Node::postSave() before updating the node access table and reindex the search table.

I'm open to any suggestions on this.

danrod’s picture

Assigned: danrod » Unassigned
Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

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

danrod’s picture

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

danrod’s picture

Status: Needs work » Needs review

acbramley made their first commit to this issue’s fork.

acbramley’s picture

Issue tags: -Needs tests

Rebased and slightly tidied up the test.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

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.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Couple of comments on the MR.

acbramley’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed.

quietone’s picture

@danrod, thanks for the issue summary update.

Everything appears to be in order here.

acbramley’s picture

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

larowlan’s picture

Credits

larowlan’s picture

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

One is an obvious typo that I'll self apply

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

@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

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

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.

catch’s picture

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.

acbramley’s picture

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.

catch’s picture

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?

danrod’s picture

Status: Needs work » Needs review

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

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.76 KB

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.

acbramley’s picture

Status: Needs work » Needs review

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

acbramley’s picture

Issue summary: View changes
acbramley’s picture

Title: Implementations of hook_node_update should check the "isDefaultRevision" property » Saving non-default revisions shouldn't trigger a search reindex
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

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.

acbramley’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

Asked a question about the test, if it's complicated we can leave it, but it's worth defaulting to kernel tests instead of slower functional ones I think.

acbramley’s picture

Status: Needs work » Needs review

Good call, swapped to a kernel test.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback for this one has been addressed and still appears to be working

catch’s picture

Status: Reviewed & tested by the community » Needs work

This needs a rebase for the RunTestsInSeparateProcess attribute

acbramley’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good

  • catch committed 0e8fff5a on 11.x
    fix: #1522154 Saving non-default revisions shouldn't trigger a search...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed f168d5c8 on 11.3.x
    fix: #1522154 Saving non-default revisions shouldn't trigger a search...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.