From f42a482b447a188ef1e4c4d9b1efa091aaa2b71d Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 09:02:35 +0000 Subject: [PATCH] Ensure entry order is set when using queue --- src/Entries/EntryRepository.php | 2 +- src/Jobs/UpdateCollectionEntryOrder.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Entries/EntryRepository.php b/src/Entries/EntryRepository.php index 4a3e00c6..85e25a7c 100644 --- a/src/Entries/EntryRepository.php +++ b/src/Entries/EntryRepository.php @@ -86,7 +86,7 @@ public function updateOrders($collection, $ids = null) ->when($ids, fn ($query) => $query->whereIn('id', $ids)) ->get(['id']) ->each(function ($entry) { - $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id()); + $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id(), $entry->order()); $connection = config('statamic.eloquent-driver.collections.update_entry_order_connection', 'default'); diff --git a/src/Jobs/UpdateCollectionEntryOrder.php b/src/Jobs/UpdateCollectionEntryOrder.php index 8cfdebce..4e07e5fb 100644 --- a/src/Jobs/UpdateCollectionEntryOrder.php +++ b/src/Jobs/UpdateCollectionEntryOrder.php @@ -12,16 +12,17 @@ class UpdateCollectionEntryOrder implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable; - public $entryId; - - public function __construct($entryId) + public function __construct(public $entryId, public $order) { - $this->entryId = $entryId; } public function handle() { if ($entry = Entry::find($this->entryId)) { + if ($this->order) { + $entry->order($this->order); + } + $entry->save(); } }