Repository navigation
[6.x] Fix entry URIs going stale when a tree file changes on disk - #15798
Open
DanielDarrenJones wants to merge 2 commits into
Open
DanielDarrenJones wants to merge 2 commits into
DanielDarrenJones wants to merge 2 commits into
Conversation
This fails on 6.x: moving a page in a collection tree file leaves the entry's URI as it was until the Stache is cleared.
Saving a tree through the API updates the entries it affects in the CollectionTreeSaved listeners. When a tree file changes on disk instead, the watcher re-reads the tree but nothing updates the entries, so their URIs (and order) stay stale. CollectionTreeStore now updates the collection's entry parents, order and URIs when the watcher picks up a changed tree, under the same conditions as UpdateStructuredEntryUris. Structured collections' entry stores check the trees for changes before their own indexes are used, since that's where their URIs come from. Fixes statamic#15796
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15796.
When a collection tree file changes on disk (after a
git pull, a deploy or a hand edit) and the Stache watcher picks it up, the tree is re-read but the entries in it aren't updated: a page moved in the tree keeps its old URI untilphp please stache:clear. Links render to the old address, andEntry::findByUri()resolves the old URL rather than the new one.Saving a tree through the API does the follow-up work in the
CollectionTreeSavedlisteners (UpdateStructuredEntryUris,UpdateStructuredEntryOrderAndParent). The watcher path dispatches no event, andCollectionTreeStorehad nohandleModifiedItem(), so nothing ran.What this changes
CollectionTreeStore::handleModifiedItem()updates the collection's entry parents, order and URIs when the watcher picks up a changed tree. It uses the same conditions asUpdateStructuredEntryUris(no URI update for single-depth structures or collections without a route). The previous tree is already gone from the cache by then, so there's no diff to narrow it to the entries that moved, and it updates the whole collection. This only runs with the watcher on.Entry::find($id)->uri(), never touches the tree store, so the change isn't noticed until something else reads a tree. Each store only checks once per request, so this can't loop.Test
FeatureTest::the_watcher_updates_entry_uris_when_a_tree_file_changesmovespages-directorsfrom under About → Board to the top level of the fixture tree file and checks the next request. On6.xit fails:uri()is still/about/board/directors. With this change it is/directors,findByUri('/directors')finds it, and the old URL no longer resolves. The fixture file is restored afterwards.The test is in its own commit, so you can see it fail before the fix:
The full suite passes with the change.