`SiteNotFoundException` thrown on collection index after deleting a site
Bug description
When deleting a site, it doesn't delete the content, navigation, or trees. Statamic sees that the content exists, but can't find the deleted site, and triggering a SiteNotFoundException.
Now that sites are editable in the CMS rather than just config php, I'd expect users with privileged access to be able to remove old sites / languages without it breaking the entire CMS experience.
How to reproduce
- Create a new site
- Enable that site in the collection
- Create a page on the new site
- Create a navigation menu on the new site
- Delete the old site
- Browse to the collections page / frontend
Logs
Environment
Environment
Application Name: MELCloud
Laravel Version: 11.44.7
PHP Version: 8.3.20
Composer Version: 2.8.8
Environment: local
Debug Mode: ENABLED
URL: melcloud-world.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 4
Sites: 26 (United Kingdom / English, Belgium / Dutch, Belgium / French, and 23 more)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.55.0 PRO
Statamic Addons
alt-design/alt-redirect: 1.6.3
mitydigital/sitemapamic: 3.2.0
statamic/eloquent-driver: 4.21.1
statamic/ssg: 3.1.1
Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: file
Collections: file
Entries: file
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Sites: file
Taxonomies: file
Terms: file
Tokens: file
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
Deleting a site shouldn't cause an error, even if the content is left behind.
Can you provide the full stack trace for the error you're seeing?
https://github.com/user-attachments/assets/a66d09c1-e892-4506-abba-11df92d74f50
See video above on a fresh site to reproduce, there's also an additional issue that when you enable multisite, the default homepage isn't moved to the default site folder and triggers an error, which can be confusing for first time users.
there's also an additional issue that when you enable multisite, the default homepage isn't moved to the default site folder and triggers an error, which can be confusing for first time users.
@SteveEdson If you want to convert an existing single site to a multi-site, you need to run the following command: php please multisite. Only then will the content also be migrated. Otherwise, you need to follow the manual migration guide:
https://statamic.dev/tips/converting-from-single-to-multi-site
@o1y sorry I'd missed that bit while recording the example. Ignore that part of the issue.
Just to add to this, it also happens for taxonomies too. If you delete a site that a taxonomy was a part of, it will throw errors in statamic/cms/src/Http/Controllers/CP/Taxonomies/TermsController.php, line 258.