Node Revision Delete
A module that automatically tracks and prunes old node revisions based on configurable plugin rules.
node_revision_delete
Install
composer require 'drupal/node_revision_delete:^2.0'
Overview
The Node Revision Delete module provides a comprehensive solution for managing and automatically deleting old node revisions in Drupal. It uses a plugin-based architecture that allows flexible configuration of deletion rules based on multiple criteria.
When new revisions are created, content is automatically added to a processing queue. The queue worker then evaluates each revision against all enabled plugins to determine if it should be deleted. The plugin system uses a voting mechanism: if any plugin returns FALSE, the revision is kept; if at least one returns TRUE and none return FALSE, the revision is deleted.
The module supports per-content-type configuration overrides, multilingual content with separate revision tracking per language, and includes Drush commands for batch operations. It integrates seamlessly with Drupal's Content Moderation workflow for managing draft revisions.
Features
- Plugin-based architecture for flexible revision deletion rules with four built-in plugins: Amount, Created, Drafts, and Only Drafts
- Automatic queueing of content when new revisions are created, with option to disable automatic queueing
- Per-content-type configuration overrides with fallback to global defaults
- Support for multilingual content with separate revision counting per language
- Batch processing UI to queue all existing content for revision cleanup
- Queue worker that processes revision deletions during cron (5-minute processing window)
- Verbose logging option to track all deleted revisions
- Integration with Content Moderation for draft revision management
- Manual bulk deletion of prior revisions from the revision delete confirmation page
- Drush commands for command-line batch operations and manual revision deletion
Use Cases
Limiting revisions by count
A news website wants to keep only the last 10 revisions of articles to save database space. Configure the Amount plugin with a minimum of 10 revisions. When an article exceeds this limit, older revisions are automatically deleted during cron processing.
Time-based revision cleanup
A corporate site needs to comply with data retention policies that require content older than 12 months to be purged. Enable the Created plugin with age set to 12 months. Revisions older than one year will be automatically deleted.
Draft revision cleanup
An editorial team creates many draft revisions during content review. To prevent database bloat, enable the Drafts plugin with a 3-month age limit. Abandoned draft revisions older than 3 months are automatically removed while preserving the published revision history.
Multilingual content management
A multilingual site maintains separate revision histories for each language. The module automatically tracks revisions per language, ensuring that the configured minimum revision count is maintained independently for each translation.
Manual bulk cleanup
During a site audit, an administrator needs to delete all revisions prior to a specific revision. Use the Drush command 'drush nrd:delete-prior-revisions [nid] [vid]' to interactively remove historical revisions, or use the UI option when deleting a revision to also delete all prior revisions.
Content Moderation workflow integration
A publishing workflow uses Content Moderation with draft, review, and published states. Enable the Only Drafts plugin to specifically target and clean up old draft revisions while preserving the full history of published content for compliance purposes.
Scheduled maintenance with disabled auto-queue
A high-traffic site wants to control when revision cleanup processing occurs. Disable automatic queueing in settings and use a scheduled task to run 'drush node-revision-delete:queue' during off-peak hours, followed by 'drush queue:run node_revision_delete'.
Tips
- Enable verbose logging during initial setup to monitor which revisions are being deleted and by which plugins
- Use the Queue UI module to monitor the node_revision_delete queue and troubleshoot processing issues
- Combine Amount and Created plugins for comprehensive coverage - Amount ensures minimum revisions while Created handles old revisions
- Test settings on a staging environment before deploying to production, especially for sites with large revision histories
- For large sites, consider disabling automatic queueing and scheduling the drush queue command during off-peak hours
- The Only Drafts plugin requires Content Moderation; for sites without workflow, use the regular Drafts plugin instead
- Back up your database before running bulk deletion operations, especially using the Drush delete-prior-revisions command
Technical Details
Admin Pages 2
/admin/config/content/node_revision_delete
Main configuration page for Node Revision Delete module. Displays a table of all content types with their current settings status (Default or Overridden) and provides access to configure each content type. Below the table, default plugin configurations can be set which apply to all content types without overrides.
/admin/structure/types/manage/{node_type}
Per-content-type configuration for Node Revision Delete, available as a vertical tab in the content type edit form. Settings here override the global defaults.
Permissions 1
Hooks 1
hook_node_revision_delete_info_alter
Alter node revision delete plugin definitions. This hook is invoked by the plugin manager to allow modules to modify plugin definitions.
Drush Commands 2
drush node-revision-delete:queue
Adds all content to a queue to delete revisions. Creates queue items for all nodes that have at least one enabled plugin, which are then processed during cron.
drush nrd:delete-prior-revisions
Deletes all revisions prior to a specified revision for a given node. Interactive command that prompts for confirmation and offers to delete the specified revision as well.
Troubleshooting 5
Ensure at least one plugin is enabled either globally or for the specific content type. Check that 'Disable automatic queueing' is not enabled. Verify cron is running regularly. Check the queue using Queue UI module or 'drush queue:list' to see pending items.
Multiple plugins can prevent deletion. If any plugin returns FALSE for a revision, it will be kept. Review all enabled plugins and their settings. The Amount plugin may be keeping revisions that the Created plugin would delete, or vice versa.
The queue worker has a 300-second time limit per cron run. For large sites, multiple cron runs may be needed. Use 'drush queue:run node_revision_delete' to manually process the queue. Consider increasing PHP memory limits for large batches.
After changing settings, the plugin manager cache needs to be cleared. Clear caches via 'drush cr' or Administration > Configuration > Development > Performance. Check that the content type shows 'Overridden' on the settings page.
The module tracks revisions per language separately. If revisions seem to be deleted incorrectly for translations, verify the revision's language affiliation by checking isRevisionTranslationAffected() on the revision.
Security Notes 3
- The 'Administer Node Revision Delete' permission should only be granted to trusted administrators as it controls content retention policies
- Revision deletion is permanent and cannot be undone - ensure proper backup procedures are in place
- The module respects Drupal's access control - the queue worker uses accessCheck(FALSE) for internal operations but this is appropriate for cron-based cleanup tasks