Structured entry order goes stale for entries shifted, but not moved, by a tree change

Đang mở
#15,799 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mynetx đang làm issue này rồi.

Từ ngày 7/11/2026.

  • #15816 của @mynetx — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
laravel, php
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start by reading UpdateStructuredEntryOrderAndParent and trace how it uses the tree diff to update flattened entry order; the report also points to CollectionEntriesStore::updateOrders($ids) for the Stache path. Reproduce the A/a1/B/b1 example, then check that adding a2 or moving an entry leaves every stored order matching the flattened tree. Consider the reported concern about the number of saves for large trees.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

stache
Bug description

When a collection tree is saved, UpdateStructuredEntryOrderAndParent only updates the order of entries in $diff->moved() and $diff->added() (plus the descendants of moved entries). An entry's order is its position in the whole flattened tree though, so any entry whose flattened position shifts without its own parent or index changing keeps its old order value.

With the Eloquent driver that value is stored in entries.order, and structured collections are sorted by it on the front end (e.g. the collection tag's default sort), so over time the site drifts away from the tree in the CP, with ties and items in the wrong place. We had a client report that reordering in the CP wasn't being reflected on the site, and on that database around 1,300 of 3,700 structured entries had a stale order.

How to reproduce
  1. Create a structured collection with this tree:
    - A
      - a1
    - B
      - b1
    
    The stored orders are A = 1, a1 = 2, B = 3, b1 = 4.
  2. Add a new entry a2 as a child of A, so the tree flattens to A, a1, a2, B, b1.
  3. a2 gets order 3, but B and b1 aren't in moved() as their path and index haven't changed, so they keep 3 and 4.
  4. B now ties with a2, b1 has 4 rather than 5, and Entry::query()->where('collection', 'x')->orderBy('order') (or {{ collection:x }}) no longer matches the tree.

The same happens when an entry is moved within one branch, as every entry after it in other branches shifts but isn't updated.

Logs

No response

Environment
Environment
Laravel Version: 12.70.0
PHP Version: 8.4.27
Composer Version: 2.10.3
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 5
Sites: 42 (English, Dutch, Russian, and 39 more)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 6.35.1 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.18.0
aryehraber/statamic-logbook: 4.1.0
mitydigital/sitemapamic: 3.5.1
statamic/eloquent-driver: 5.12.3
statamic/ssg: 4.1.0

Statamic Eloquent Driver
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Installation

Existing Laravel app

Additional details

I've only confirmed this with the Eloquent driver. From reading the code I think the Stache's order index would go stale in the same way, as CollectionEntriesStore::updateOrders($ids) only calls updateItem() for the ids it's given, but it's rebuilt on stache:warm so it's probably much less noticeable there.

One option would be to work out the affected ids by comparing each entry's position in the old and new flattened trees, rather than its path and index. I appreciate that could mean a lot of saves on bigger trees (statamic/eloquent-driver#105), so happy to go with whichever approach you'd prefer.

For now we've worked around it with a CollectionTreeSaved listener that writes each entry's flattened position straight to the order column, only for rows where it's wrong.

Ngôn ngữ chính
PHP
Star
4.9k
Fork
647
Merge trung bình
1 ngày 45 phút
Pull request đã merge (30 ngày)
221

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của statamic/cms

Tất cả issue của statamic/cms

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.