Problem/Motivation
I was testing the following scenario:
1. Enable content moderation on articles
2. Create a published version of an article node.
3. Configure this module to keep 10 revisions as history.
4. Created 10 new draft revisions. This makes the currently published revision eligible for deletion.
5. Cleared the now reported for delete revisions from the UI batch operation.
Result was that the current revision that was the published node the 11th one got deleted or another one was deleted that was after it.
After checking the same things in DB on the node and node_revision tables the thing deletes revisions created after the published one.
The published revision is not deleted, but the one after it was.
Essentially this will break revisions graph at some point in time. I think it's OK to keep draft revisions. Once some of them get's published - it will move up the chain and free the older ones for deletion.
Proposed resolution
Is this behavior OK in terms of data consistency?NoCan we have one more checkbox on the configuration UI that will preserve revisions that are newer than the currently published revision?- TBD
Remaining tasks
Consensus on problemConsensus on solution
Tasks for this Plan (More tasks need to be added):
#3127419: Add a configuration to delete revisions newer than the current revision
#3127424: Set the default value for delete_newer configuration variable
#3128035: Use the delete_newer configuration variable to identify the candidates revisions
#3128068: Check in the Kernel test the default value of delete_newer
#3128070: Check the config variable delete_newer in the Functional test
User interface changes
TBD.
API changes
TBD.
Data model changes
TBD.
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | node_revision_delete-delete_draft-3094354-18-D8.patch | 1.16 KB | adriancid |
Comments
Comment #2
adriancidHi, thanks for the issue and for use the Issue Summary Template.
We can't delete the current revision of a node, and I can't get the point of what are you proposing here.
Comment #3
ndobromirov commentedLet's simplify - let's keep the last 5 revisions.
Then you have the following set
6, 5, 4, 3, 2, 1 (published)
After the module does it's magic the result revision IDs are
6, 5, 4, 3, 1 (published)
The 2 one is missing. It was not the published one, but it was created after it.
Depending on what get's done with revisions (content moderation, etc)
So the proposal is to delete whatever needs to be deleted prior the published revision, but keep revisions that are newer than the published one.
Comment #4
adriancidI think this made sense. And is easy to accomplish as we only need to add a condition to the query searching for the revision candidates.
Do you want to create the patch?
Comment #5
ndobromirov commentedNo time to make a patch at the moment...
Comment #6
jasonawantAdding related issue #3118464: Add support for "Maximum number allowed" revisions per content node translation
Comment #7
jasonawantThis has become a priority for our stakeholders. We will begin to outline a solution and plan to include it in future sprint work.
It sounds like @adriancid confirmed that Node Revision Delete should/could account for this and is accepting of patches!
So on to a solution. I'm not sure the UI needs another checkbox to indicate this an optional functionality. I recommend the query logic should account for this by default. Thoughts?
I will post again after I've had time to review logic and propose a solution.
Comment #8
adriancid@jasonawant I think we just need to check if the conditions are present and add the conditions to the query, as I think this is the logical behavior.
Comment #9
jasonawantThanks @adriancid!
Sounds like the OP was recommending protecting all revisions that were created after the current published revision. Protecting revisions by omitting matching records using node_revision.revision_timestamp > node.changed or node_field_revision.changed > node_field_data.changed? Is that your understanding?
Comment #10
jasonawantAlright, here's a pass at different query logic to exclude future (draft, moderation state could be anything) revisions. I wanted to post now while I continue to prepare a patch for review. My patch will include changes for #3118464: Add support for "Maximum number allowed" revisions per content node translation.
This query logic would replace the logic found in NodeRevisionDelete::getCandidatesRevisionsByNids();
Current logic
Replacement
This approach does require ordering by change date and offsetting the range b/c it excludes the current and future revisions by joining on the node_field_data's nid and changed timestamp.
I'm a little unsure with having two conditions for when_to_delete and minimum_age_to_delete, seems redundant but probably doesn't hurt.
Note the langcode condition. This is new to account for #3118464: Add support for "Maximum number allowed" revisions per content node translation.
Comment #11
jasonawantShoot, I guess can't scale b/c of I've made an assumption about looping over the $candidate_nodes, which would generate a query per node, see this condition in the above replacement,
$query->condition('nfr.nid', $candidate_node, '=');I'll take another look at this.
Comment #12
jasonawantWell, here's a draft patch that also includes #3118464: Add support for "Maximum number allowed" revisions per content node translation work as well.
Comment #13
jasonawantI've caught a few issues with previous patch.
Comment #14
jasonawantPer #3118464-11: Add support for "Maximum number allowed" revisions per content node translation, here's a patch for this issue only that does not account for per content translations.
Comment #15
adriancid@jasonawant thanks, it is better for me always review small patches or patches for small tasks, as I don't have much time to do it and I contribute in my free time. I will check this in the next days and then we can continue with the other issue.
Comment #16
semiaddict commentedHi,
I'm also experiencing issues related to drafts being deleted when using the content_moderation core module.
I haven't had the time to look into this, but wouldn't simply changing
to
prevent drafts that are newer than the current revision from being deleted ?
Comment #17
adriancid@semiaddict yes, the change is simple, but the patch is trying to fix the problem with the language too (this is why is more complex), I just need to find time in these crazy virus days to take a look into the patch.
Comment #18
adriancid@semiaddict you're right, I mixed the issues, this is the only thing we need here.
@jasonawant the query you're trying to build doesn't work, I tested the query and I'm not getting all the revisions I should by getting concerning the issue description.
I'm uploading a patch to be tested and I think we will need to add in someplace a description about the module behavior and then I will commit the patch.
Comment #19
jasonawant@adriancid,
That seems like a simply fix here! I probably over complicated this b/c I was coming from #3118464: Add support for "Maximum number allowed" revisions per content node translation. Hopefully, there's just as simple fix for that issue too.
Regarding,
Which patch were you trying?
Comment #20
adriancid@jasonawant I'm talking about #14 this is the patch I was testing and it doesn't work, can you test the patch I submitted #18?
Comment #21
jasonawantThanks for the info!
tested, and works expected. Tested with patch, it preserves a draft revision. Tested w/out patch, draft revision is deleted.
Setting back to needs work
Comment #22
adriancid@jasonawant thanks, I will see where is the better place to explain this behavior, maybe I will need to write in many places (readme, help, and configs)
Comment #23
semiaddict commentedI am wondering if this behavior should be optional instead of hard-coded.
Some might still want drafts to be deleted if they exceed a certain number, thus the current behavior (before patch) could fit their need.
What do you think ?
I might be able to put in an hour or so next week to take care of this.
Comment #24
adriancidGod point @semiaddict I will work on this, I think it is better like an option, in this case, I will turn this into a plan and I will add some child issues as we will need to add explanations about this in some places. Just keep an eye on the issue queue to help me reviewing the issues. You can change the notifications for the project in https://www.drupal.org/project/issues/subscribe-mail/node_revision_delet...
Comment #25
adriancidComment #26
adriancidComment #27
adriancidComment #28
adriancidI think all the issues cover the new functionality, as we will need at some point to write all the help pages I think is better to wait until this moment to do it for this feature. For the moment I add a description in the configuration form.
Comment #29
adriancidComment #30
adriancidComment #31
adriancidComment #32
adriancid