Problem/Motivation

I read thru the code a noticed that there are no cron tasks to add outdated revisions to the queue.
The queue adding relies on the node_update hook to check if the conditions are met, but if the nodes are not saved then they are not added to the queue.

Steps to reproduce

  • Set option "Delete revisions after a specific amount of time." enabled
  • Set the min time 1 month and save
  • Wait for 1 month without saving your nodes with outdated revisions
  • Your revision are undeleted after the month

Proposed resolution

New interface: NodeRevisionDeleteTimeBasedInterface::getDelay()

A getDelay(NodeInterface $revision) method is added to the NodeRevisionDeleteTimeBasedInterface. Each time-based plugin calculates exactly how many seconds remain until the given revision becomes eligible for deletion, based on the revision's changed time, the plugin's configured age threshold, and the current time. The Created and OnlyDrafts plugins both implement the new interface.

Queue worker changes

NodeRevisionDelete::doProcessItem()now:

  • Tracks which time-based plugin protects which VIDs, per language.
  • Identifies revisions that are exclusively time-protected (not also protected by a non-time-based plugin like Amount).
  • For each time-based plugin, finds the highest exclusively-time-protected VID per language, loads the revision in the correct translation, and asks the plugin for its delay.
  • Uses min($delays) — the shortest delay across all plugins — as the requeue time. This ensures the node is rechecked as soon as the first revision becomes eligible.

New queue worker: NodeRevisionDeleteRequeue

A new node_revision_delete_requeue queue worker processes delayed requeue items. Each item contains a nid and a requeue_time timestamp. If the requeue time hasn't arrived, it throws DelayedRequeueException. Once the time arrives, it moves the node back to the main node_revision_delete queue for reprocessing. The new queue exists to ensure that requeued nodes do prevent other nodes from entering the NodeRevisionDelete queue.

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

onnia created an issue. See original summary.

bdunphy’s picture

Can confirm and I have bumped against this bug as well. This makes the module less useful in production uses. Having to save the outdated node in order to queue up revision deletion is not practical.

bwaindwain’s picture

Same here. We chose to use the "Delete revisions after a specific amount of time." and set it to 6 months. But nodes are only processed once after a save, then removed from the queue and never checked again. So, inactive nodes never get cleaned up.

We had to write our own hook_cron() similar to above.

To clean up manually, use drush commands or the GUI "Queue all content to delete revisions in the background."

alexpott’s picture

Priority: Normal » Major

I think this is a major bug for the module.

acbramley’s picture

Version: 2.0.0 » 2.0.x-dev

There is a drush node-revision-delete:queue command which will queue every single nid for every single content type that has enabled plugins (i.e all of them if it's just using default config).

When evaluating this module, that was the one glaring issue I found, there's no way to either a) batch queue existing content, or b) use plugin logic to find existing revisions that can be deleted without updating the nodes.

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

plopesc’s picture

Status: Active » Needs review

To try to address this scenario for our use case, we worked on the MR above.

It declares a new interface for NodeRevisionDeleteCronInterface that allows individual NodeDeleteRevision plugins to implement their specific periodical tasks.

Created plugin makes use of this interface to declare a cron method that loads a small number of entities whose revisions should be deleted and add them to the queue.

alexpott’s picture

Version: 2.0.x-dev » 2.1.x-dev

This is a big new feature that involves a new interface - this is only going to land on the 2.1.x branch.

alexpott’s picture

The current approach has a problem because node_revision_delete plugins can be combined and it is possible that the plugin will only ever requeue content that has revisions that are being kept due to other plugins and therefore it'll stop working. Fixing this is a bit complicated. Not sure of the best solution. I'm thinking that we need to store the highest nid we get from the cron query and use that next time as the minimum nid. When we get no result we set the minimum nid back to 0. That way we constantly check new nodes so nothing gets stuck due to other rules.

alexpott changed the visibility of the branch 3512434-outdated-revisions-are to hidden.

alexpott’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated issue summary with details of the change.

  • alexpott committed 08ba6b28 on 2.1.x
    fix: #3512434 Outdated revisions are not added to queue unless they are...
alexpott’s picture

Status: Reviewed & tested by the community » 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.

Status: Fixed » Closed (fixed)

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