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
| Comment | File | Size | Author |
|---|
Issue fork drupal-1522154
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
Comment #1
stevectorComment #3
gábor hojtsyRetitled for the current implementation.
Comment #4
hass commentedI 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.
Comment #5
stevectorThanks 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.
Comment #6
stevectorReroll.
Comment #22
berdirI 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.
Comment #23
danrodI attached a patch that checks for
isDefaultRevision()being set to TRUE before runningnode_reindex_node_searchand same situation forcommentInsertorcommentUpdateand orcommentDeleteat/core/modules/node/src/Hook/NodeHooks1.phpI'm starting to do some Core contribution for the first time so bear with me when reviewing.
Comment #24
danrodComment #25
berdirAll contributions must be merge requests.
Comment #28
sivaji_ganesh_jojodae commentedCreated MR to reflect the above comments.
Comment #29
danrodThanks @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.
Comment #30
smustgrave commentedHave not reviewed but issue summary appears incomplete
Comment #31
danrodI improved the issue summary, hope it makes more sense.
Comment #32
danrodComment #33
danrodComment #34
danrodComment #35
smustgrave commentedLeft some comments on the MR.
Comment #36
danrodComment #37
danrodComment #38
danrodComment #39
danrodI documented the
$commentparameter, added some more information and created a simple$this->assertTrue()in thetestDeterminingChanges()test method (filecore/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.
Comment #40
danrodComment #41
smustgrave commentedLeaving tests tag as the test-only pipeline is passing when I'd expect it to fail.
Comment #42
danrodI 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
Comment #43
danrodComment #45
acbramley commentedRebased and slightly tidied up the test.
Comment #46
smustgrave commentedRan testonly feature
Shows the coverage
Summary appears to be complete and matches the solution.
Believe all feedback has also been addressed.
Comment #47
catchCouple of comments on the MR.
Comment #48
acbramley commentedComment #49
smustgrave commentedFeedback appears to be addressed.
Comment #50
quietone commented@danrod, thanks for the issue summary update.
Everything appears to be in order here.
Comment #51
acbramley commentedRebased and made some slight tweaks to the test so we don't need to install search module for every other test case in NodeSaveTest
Comment #52
larowlanCredits
Comment #53
larowlanCouple of questions on the MR, keeping at RTBC for now
One is an obvious typo that I'll self apply
Comment #54
larowlan@berdir flagged in #22
They are as follows:
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
Comment #55
needs-review-queue-bot commentedThe 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.
Comment #56
catchI 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.
Comment #57
acbramley commentedRe #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.
Comment #58
catchI 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?
Comment #59
danrodI've moved this to "Needs Review" just in case you decide to go ahead with the MR.
Comment #60
needs-review-queue-bot commentedThe 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.
Comment #61
acbramley commentedThe solution was updating outdated (and deprecated) code. I've rebased and squashed the MR with the new fix.
Comment #62
acbramley commentedComment #63
acbramley commentedComment #64
needs-review-queue-bot commentedThe 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.
Comment #65
acbramley commentedComment #66
berdirAsked 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.
Comment #67
acbramley commentedGood call, swapped to a kernel test.
Comment #68
smustgrave commentedBelieve feedback for this one has been addressed and still appears to be working
Comment #69
catchThis needs a rebase for the RunTestsInSeparateProcess attribute
Comment #70
acbramley commentedComment #71
smustgrave commentedRebase seems good
Comment #73
catchCommitted/pushed to 11.x and cherry-picked to 11.3.x, thanks!