Problem/Motivation

When using Revision manager with Group module I'm able to setup correct policy (number of revisions to keep and timespan), Group entities are correctly added to the queue, but when queue is processed all excessive Group revisions are still in place. All other entity types (Content) processed correctly, only Group entities are a problem.

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

jura.khrapunov created an issue. See original summary.

j-barnes’s picture

@jura.khrapunov - Thanks for reporting this. I've been trying to replicate this locally with tests but no luck.

I've went ahead and added a few new group specific tests for your exact scenario.

  • testAgeAndAmountPluginsGroup - Both plugins enabled, old revisions deleted correctly
  • testAgeAndAmountAllRecentGroup - All recent revisions protected (intersection logic)
  • testAmountWouldDeleteAgeProtectsGroup - Age protects recent revisions from Amount deletion



All tests seem to pass, including the combined Age + Amount scenario you described.

When both plugins are enabled, revisions are only deleted if they appear in BOTH deletion sets (intersection):

  • If all your revisions are recent (< 6 months), Age returns empty → nothing deleted
  • If you have fewer revisions than your Amount threshold, Amount returns empty → nothing deleted
  • Only revisions that are BOTH old enough AND exceed the count get deleted

A few questions to help debug:

  1. Group module version? (2.x vs 3.x)
  2. Drupal core version?
  3. How old are the Group revisions?
  4. How many revisions exist vs your Amount threshold?
  5. Are the revisions published (status=1)?
jura.khrapunov’s picture

@j-barnes, thanks for looking into this. I understand the logic and it works just fine for all other entities, but groups, unfortunately. Just a note - Group support was a sole reason to switch from node_delete_revision module which doesn't support them.

Group module version: 2.3.2
Drupal version: 11.2.5
Group revisions: for the test entity the oldest is from 2022, most recent is from a week ago
How many revisions exist vs your Amount threshold? 58 revisions exist, threshold in Revision manager is set to 10
Are the revisions published: yes, all of them

If it helps - I was able to delete excessive revisions via drush using another module of yours: drupal/revision_delete_tools , but it doesn't work for me as it is not working well with multilingual entities.

j-barnes’s picture

StatusFileSize
new3.21 KB

Thanks for the extra details - I think I was able to replicate this. The issue appears to be in EntityHelper::getEntityIds() - it was using accessCheck(TRUE) which triggers Group's access hooks when enumerating entities. During drush/cron runs, Group tries to check memberships and silently fails, so no entities get found for cleanup.

The fix should be straightforward - change to accessCheck(FALSE) since this is an admin operation and it follows the same pattern as core for batch processing.

Opening a MR with a patch and test, let me know if it works for you.

j-barnes’s picture

Version: 1.0.0-beta2 » 1.0.x-dev
Assigned: Unassigned » j-barnes
Status: Active » Needs review
jura.khrapunov’s picture

@j-barnes, I tried the patch you provided and it seems it does the job.

However, I noticed in our case we had fair amount of revisions (mostly very old) with status=0. Those revisions are not affected by cleanup but they are still taken into consideration for calculations of the number of revisions to retain, which leads to undesired results.

Here is an example:

Group has 50 revisions spread between 2022 and 2025 years. There are 10 revisions from 2022 with the status=0, so when Revision manager is configured to keep last 5 versions we are ending up with exactly 11 revisions - the most current one plus 10 very old which are kept because of their status=0.
Expected behavior would be to keep 5 most recent revisions (or any number within "Minimum age of revisions to keep" period). I'd also suggest to remove revisions with status=0 if there are newer revisions, is there particular reason to exclude them?

j-barnes’s picture

Thanks for confirming the patch works and helping out with this.

Yeah, the status=0 accumulation is a valid concern. We protect unpublished revisions by design (could be draft work), but 3-year-old drafts are probably safe to clean up.

I dug into how node_revision_delete handles this - they use a 3 state system keep/delete/no-opinion on each revision. I'm thinking of adopting that for 2.x, which would let us add a WorkflowState plugin:

  • Pick which moderation states can be deleted (draft, archived, etc.)
  • Separate age threshold for those states
  • Falls back to status=0 when Content Moderation isn't enabled

That way you get separate policies for published vs draft cleanup. What do you think about that? We can spin this off into a separate issue.

jura.khrapunov’s picture

I think it is more logical to keep drafts which are more recent than the published revision only. If the new revision supersedes existing draft - in our editorial workflow it makes older version obsolete and subject for clean up. With "Minimum age of revisions to keep" it provides great flexibility to accommodate various scenarios, but frankly speaking if the draft is older than current published version - I don't see why it should be protected. if you would like to accommodate that scenario - it might be worth adding another checkbox to the RM settings: "Keep all drafts".

It is a different story if the draft is more recent than the published version and those must be preserved, but as far as I can see It is already discussed here: https://www.drupal.org/project/revision_manager/issues/3556356

jura.khrapunov’s picture

My primary concern is that with drafts included into the calculations we are facing potential data loss - I'd expect to keep XYZ number of the most recent versions for the node, but instead it leaves me with the only one, which is currently published and random number of old drafts associated with the node.

j-barnes’s picture

Yeah you're right - we can just protect forward drafts and treat old drafts as regular deletion candidates. Way simpler than what I was originally thinking...

Basically change the Amount / Age plugin from filtering by status=1:

$buckets = $this->getRevisionIds($entity, [
  ['field' => $this->getStatusField($entity), 'value' => 1],
]);

To filtering by revision ID:

$revisionKey = $entity->getEntityType()->getKey('revision');
$current = (int) $entity->getRevisionId();

$buckets = $this->getRevisionIds($entity, [
  ['field' => $revisionKey, 'value' => $current, 'operator' =>
'<'],
]);

This also handles #3556356 (forward revisions) since they're automatically excluded from the query.

What do you think? I can throw together a patch with some tests to confirm it works as expected, it might be better on the other issue though.

jura.khrapunov’s picture

@j-barnes I think you nailed it this time. Future revisions are not included and the rest is processed using common logic. Happy to test the patch on the real database clone.

j-barnes’s picture

StatusFileSize
new15.12 KB

Thanks again for taking the time to test this out, added the new patch.

jura.khrapunov’s picture

Works as expected now, but another issue popped up as long trail of unremoved drafts is not covering it now - algorithm is not aware of translations and count all respective revisions together, same as https://www.drupal.org/project/revision_delete_tools. I'll open a separate ticket for that issue as this one is apparently fixed now.

Thank you for spending time on this, really appreciated.

j-barnes’s picture

Awesome, glad it's working now. Thanks for testing - good catch on the translation issue too, I'll take a look.

j-barnes’s picture

Status: Needs review » Fixed

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.

  • j-barnes committed 55d6f725 on 1.0.x
    Issue #3561559: Fix Group entities not being found during batch...

Status: Fixed » Closed (fixed)

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