diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index a96358a074..f3bb0e400c 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -475,6 +475,13 @@ public function updateEntryOrder($ids = null) return $this; } + public function updateEntryParent($ids = null) + { + Facades\Collection::updateEntryParent($this, $ids); + + return $this; + } + public function path() { return vsprintf('%s/%s.yaml', [ diff --git a/src/Entries/UpdateStructuredEntryOrder.php b/src/Entries/UpdateStructuredEntryOrderAndParent.php similarity index 82% rename from src/Entries/UpdateStructuredEntryOrder.php rename to src/Entries/UpdateStructuredEntryOrderAndParent.php index 49dfbef110..aacc99da58 100644 --- a/src/Entries/UpdateStructuredEntryOrder.php +++ b/src/Entries/UpdateStructuredEntryOrderAndParent.php @@ -4,7 +4,7 @@ use Statamic\Events\CollectionTreeSaved; -class UpdateStructuredEntryOrder +class UpdateStructuredEntryOrderAndParent { public function handle(CollectionTreeSaved $event) { @@ -19,5 +19,6 @@ public function handle(CollectionTreeSaved $event) } $collection->updateEntryOrder($ids); + $collection->updateEntryParent($ids); } } diff --git a/src/Providers/EventServiceProvider.php b/src/Providers/EventServiceProvider.php index 26d95c4656..f0df91a4f6 100755 --- a/src/Providers/EventServiceProvider.php +++ b/src/Providers/EventServiceProvider.php @@ -18,7 +18,7 @@ class EventServiceProvider extends ServiceProvider ], \Statamic\Events\CollectionTreeSaved::class => [ \Statamic\Entries\UpdateStructuredEntryUris::class, - \Statamic\Entries\UpdateStructuredEntryOrder::class, + \Statamic\Entries\UpdateStructuredEntryOrderAndParent::class, ], \Statamic\Events\EntryBlueprintFound::class => [ \Statamic\Entries\AddSiteColumnToBlueprint::class, diff --git a/src/Stache/Repositories/CollectionRepository.php b/src/Stache/Repositories/CollectionRepository.php index 4412d89053..b57c7412e3 100644 --- a/src/Stache/Repositories/CollectionRepository.php +++ b/src/Stache/Repositories/CollectionRepository.php @@ -92,6 +92,11 @@ public function updateEntryOrder(Collection $collection, $ids = null) $this->store->updateEntryOrder($collection, $ids); } + public function updateEntryParent(Collection $collection, $ids = null) + { + $this->store->updateEntryParent($collection, $ids); + } + public function whereStructured(): IlluminateCollection { return $this->all()->filter->hasStructure(); diff --git a/src/Stache/Repositories/CollectionTreeRepository.php b/src/Stache/Repositories/CollectionTreeRepository.php index df6c5dc382..099fa46eee 100644 --- a/src/Stache/Repositories/CollectionTreeRepository.php +++ b/src/Stache/Repositories/CollectionTreeRepository.php @@ -3,8 +3,6 @@ namespace Statamic\Stache\Repositories; use Statamic\Contracts\Structures\CollectionTree as TreeContract; -use Statamic\Contracts\Structures\Tree; -use Statamic\Facades\Stache as StacheFacade; use Statamic\Stache\Stache; use Statamic\Structures\CollectionTree; @@ -22,16 +20,4 @@ public static function bindings() TreeContract::class => CollectionTree::class, ]; } - - public function save(Tree $tree) - { - $result = parent::save($tree); - - StacheFacade::store('entries') - ->store($tree->collection()->handle()) - ->resolveIndexes() - ->each->update(); - - return $result; - } } diff --git a/src/Stache/Stores/CollectionsStore.php b/src/Stache/Stores/CollectionsStore.php index b3cf9ebe6d..60db23f3a7 100644 --- a/src/Stache/Stores/CollectionsStore.php +++ b/src/Stache/Stores/CollectionsStore.php @@ -100,6 +100,15 @@ public function updateEntryOrder($collection, $ids = null) $this->updateEntriesWithinIndex($index, $ids); } + public function updateEntryParent($collection, $ids = null) + { + $index = Stache::store('entries') + ->store($collection->handle()) + ->index('parent'); + + $this->updateEntriesWithinIndex($index, $ids); + } + private function updateEntriesWithinIndex($index, $ids) { if (empty($ids)) {