Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Update entry URIs when collection route is changed #11150

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [];
Expand Down Expand Up @@ -486,6 +487,10 @@ public function save()

Facades\Collection::save($this);

if ($this->isDirty('route')) {
Facades\Entry::updateUris($this);
}

Blink::forget('collection-handles');
Blink::forget('mounted-collections');
Blink::flushStartingWith("collection-{$this->id()}");
Expand All @@ -498,6 +503,8 @@ public function save()
CollectionSaved::dispatch($this);
}

$this->syncOriginal();

return $this;
}

Expand Down Expand Up @@ -928,4 +935,9 @@ public function augmentedArrayData()
'handle' => $this->handle(),
];
}

public function getCurrentDirtyStateAttributes(): array
{
return $this->fileData();
}
}
1 change: 1 addition & 0 deletions tests/Data/Entries/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading