From 3957c6b70b1dbb1fe730cac28069255e9fe7dc17 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 20 Nov 2024 17:51:35 +0000 Subject: [PATCH 1/3] Update entry URIs when collection route is changed --- src/Entries/Collection.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 8c89afe4be..47a91bc62b 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -10,6 +10,7 @@ use Statamic\Data\ContainsCascadingData; use Statamic\Data\ExistsAsFile; use Statamic\Data\HasAugmentedData; +use Statamic\Data\HasDirtyState; use Statamic\Events\CollectionCreated; use Statamic\Events\CollectionCreating; use Statamic\Events\CollectionDeleted; @@ -34,7 +35,7 @@ class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contract { - use ContainsCascadingData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData; + use ContainsCascadingData, ExistsAsFile, FluentlyGetsAndSets, HasAugmentedData, HasDirtyState; protected $handle; protected $routes = []; @@ -484,6 +485,10 @@ public function save() } } + if ($this->isDirty('route')) { + Facades\Entry::updateUris($this); + } + Facades\Collection::save($this); Blink::forget('collection-handles'); @@ -498,6 +503,8 @@ public function save() CollectionSaved::dispatch($this); } + $this->syncOriginal(); + return $this; } @@ -928,4 +935,9 @@ public function augmentedArrayData() 'handle' => $this->handle(), ]; } + + public function getCurrentDirtyStateAttributes(): array + { + return $this->fileData(); + } } From 395852c08f66378a656f4398ceba627a8c2f531b Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 20 Nov 2024 18:15:55 +0000 Subject: [PATCH 2/3] move this after we save --- src/Entries/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 47a91bc62b..3cb3c86d6e 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -485,12 +485,12 @@ public function save() } } + Facades\Collection::save($this); + if ($this->isDirty('route')) { Facades\Entry::updateUris($this); } - Facades\Collection::save($this); - Blink::forget('collection-handles'); Blink::forget('mounted-collections'); Blink::flushStartingWith("collection-{$this->id()}"); From bc68defc41103f152d96341228d6e1964e6e62cb Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 20 Nov 2024 18:21:34 +0000 Subject: [PATCH 3/3] Fix failing test. --- tests/Data/Entries/CollectionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Data/Entries/CollectionTest.php b/tests/Data/Entries/CollectionTest.php index a751ec419f..7f1a01943d 100644 --- a/tests/Data/Entries/CollectionTest.php +++ b/tests/Data/Entries/CollectionTest.php @@ -504,6 +504,7 @@ public function it_saves_the_collection_through_the_api() Facades\Blink::shouldReceive('forget')->with('collection-handles')->once(); Facades\Blink::shouldReceive('forget')->with('mounted-collections')->once(); Facades\Blink::shouldReceive('flushStartingWith')->with('collection-test')->once(); + Facades\Blink::shouldReceive('once')->with('collection-test-structure', \Mockery::any())->andReturnNull(); $return = $collection->save();