Skip to content

Commit

Permalink
[4.x] Update entry order and uri by ids (#9350)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliawarnke authored Jan 18, 2024
1 parent 8f95105 commit 63fe81e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/Stache/Stores/CollectionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Stache\Stores;

use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Path;
use Statamic\Facades\Site;
use Statamic\Facades\Stache;
Expand Down Expand Up @@ -81,18 +82,32 @@ protected function getDefaultPublishState($data)

public function updateEntryUris($collection, $ids = null)
{
Stache::store('entries')
$index = Stache::store('entries')
->store($collection->handle())
->index('uri')
->update();
->index('uri');

$this->updateEntriesWithinIndex($index, $ids);
}

public function updateEntryOrder($collection, $ids = null)
{
Stache::store('entries')
$index = Stache::store('entries')
->store($collection->handle())
->index('order')
->update();
->index('order');

$this->updateEntriesWithinIndex($index, $ids);
}

private function updateEntriesWithinIndex($index, $ids)
{
if (empty($ids)) {
return $index->update();
}

collect($ids)
->map(fn ($id) => Entry::find($id))
->filter()
->each(fn ($entry) => $index->updateItem($entry));
}

public function handleFileChanges()
Expand Down

0 comments on commit 63fe81e

Please sign in to comment.