Skip to content

[6.x] Remove site content when a site is deleted - #15364

Open
ryanmitchell wants to merge 1 commit into
statamic:6.xfrom
ryanmitchell:fix/remove-site-content-on-site-delete
Open

[6.x] Remove site content when a site is deleted#15364
ryanmitchell wants to merge 1 commit into
statamic:6.xfrom
ryanmitchell:fix/remove-site-content-on-site-delete

Conversation

@ryanmitchell

@ryanmitchell ryanmitchell commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #11796

Sites::save() fires SiteDeleted per removed site but nothing cleaned up that site's content, so orphaned entries/trees/localizations remained and CollectionsController::getAuthorizedSitesForCollection() threw SiteNotFoundException on the stale handle still listed in each collection's sites config. This may have been intentional in the initial implementation but it's causing real world issues.

Fixed with a SiteDeleted subscriber that cascades cleanup synchronously.
Taxonomies/Term.php has 2 new methods - removeLocalization() + hasLocalization()

Behaviour on site deletion:

  • Collections — detachLocalizations() re-roots surviving-site localizations, then the site's entries and its collection tree are deleted, and the site is removed from Collection::sites().
  • Taxonomies — site removed from Taxonomy::sites(); each term loses that locale's data; a term with no localizations left is deleted; if the removed site was a term's root locale, a surviving localization is promoted so the term file stays valid.
  • Navigations — the per-site nav tree is deleted (Nav::sites() is derived from trees).
  • Globals — site + any origins pointing at it are removed from the set's sites map; the orphaned localization is dropped on save.

Any origin-linked content is flattened when its origin site is removed.

Known limitations:

  • entry/term revision history isn't purged (matches Entry::delete() today);
  • a chained origin (A←B←C) flattens to independent roots rather than re-parenting onto the surviving root (let me know if you'd prefer this to re-parent.
  • statamic/eloquent-driver subclasses Term and will need its own removeLocalization for DB-backed term rows if/when this merges.

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.

SiteNotFoundException thrown on collection index after deleting a site

1 participant