Skip to content

[6.x] Delete revisions when an entry is deleted - #15499

Merged
jasonvarga merged 4 commits into
statamic:6.xfrom
ecomunicare:fix/cleanup-revisions
Sep 28, 2026
Merged

jasonvarga merged 4 commits into
statamic:6.xfrom
ecomunicare:fix/cleanup-revisions

Conversation

@ecomunicare

Copy link
Copy Markdown
Contributor

Deleting an entry left its revisions in storage. They live under collections/{collection}/{locale}/{id} in the revisions directory, which defaults to storage/statamic/revisions and can be changed with path in config/statamic/revisions.php or with STATAMIC_REVISIONS_PATH. The working copy is stored there too. After the entry was gone, those files were still on disk.

Entry::delete() now calls deleteRevisions() after the entry is removed and before EntryDeleted is dispatched. deleteRevisions() deletes each revision and the working copy through Revision::delete(), so RevisionDeleted still fires and Git keeps tracking the files. The file repository then removes the entry's revision directory once it is empty. The path comes from the revisions store, so a custom path is honored. Parent directories are left in place because other entries share them.

The same delete() path covers quiet deletes, collection deletes, and localized entries. Choosing to delete localizations removes each localization's revisions as well, because each one has its own revision key. If EntryDeleting cancels the delete, or the localizations are detached instead of deleted, their revisions stay.

The repository contract is unchanged. With the Eloquent driver, Revision::delete() uses that package's repository and removes the database rows. The empty-directory cleanup stays in the file repository and does not run for Eloquent.

Covered by tests for a normal delete, other entries left intact, a cancelled delete, deleteQuietly(), and a custom revisions path.

ecomunicare and others added 2 commits September 22, 2026 11:01
Revisions and the working copy were left in the revisions store after an entry was removed. Delete them through the revision repository so the configured storage path and the Eloquent driver are both respected, and drop the entry directory once it is empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
Windows keeps backslashes from __DIR__, while the revisions store tidies paths to forward slashes, so the prefix assertion failed on that platform.

Co-authored-by: Cursor <cursoragent@cursor.com>

@jasonvarga jasonvarga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing $entry->deleteQuietly() will delete revisions loudly, triggering all sorts of events. Please add a deleteRevisionsQuietly method that calls deleteQuietly on each Revision.

A quiet entry delete was still firing RevisionDeleted for each leftover revision and working copy. Follow the core withEvents pattern so those deletes stay silent.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ecomunicare

Copy link
Copy Markdown
Contributor Author

Thanks @jasonvarga for your feedback! PR updated, now is handled properly, when an entry is deleted quietly, its revisions are also deleted quietly.

And thanks to your patience too, it's our first contribution to the project ;)

Git automation dispatches a unique commit job per content event, so the first event wins the commit message. Deleting revisions before EntryDeleted meant entry deletions were committed as "Revision deleted".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga dismissed their stale review September 28, 2026 17:57

Changes made

@jasonvarga
jasonvarga merged commit af14e7e into statamic:6.x Sep 28, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants