cms
cms copied to clipboard
[4.x] Update entry parent index on collection tree save
We've noticed an issue where parent values are not updated in the stache index in certain circumstances, producing incorrect query results. For example:
Create a collection thats's orderable but can have multiple roots, then query all the root entries (no parent):
{{ collection:index_test parent:exists="false" }}
{{ title }} - <a href="{{ url }}">{{ url }}</a><br>
{{ /collection:index_test }}
That will list all the root entries. Now do either of these:
- In the tree view move a root entry under a parent, save.
- Re-run the query above and the entry will still be listed, but it shouldn't.
- Create a new entry, set the parent, save.
- Re-run the query above and the new entry will be listed, but it shouldn't.
- Going into the entry and re-saving corrects this.
There's also https://github.com/statamic/cms/issues/5457 and https://github.com/statamic/cms/issues/5938 which may be the same issue or related to this issue, I'm not 100% sure.
This PR fixes it by updating the existing UpdateStructuredEntryOrder listener to also update the parent index.
I couldn't figure out the right way or place to do the test, if you can point me in the right direction I'll add that in.