From f42a482b447a188ef1e4c4d9b1efa091aaa2b71d Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 09:02:35 +0000 Subject: [PATCH 1/6] 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(); } } From d99f0e7c57e94ed824b13ed615ca569eb95bceff Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 09:07:25 +0000 Subject: [PATCH 2/6] Change var name --- src/Jobs/UpdateCollectionEntryOrder.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Jobs/UpdateCollectionEntryOrder.php b/src/Jobs/UpdateCollectionEntryOrder.php index 4e07e5fb..5e08ed26 100644 --- a/src/Jobs/UpdateCollectionEntryOrder.php +++ b/src/Jobs/UpdateCollectionEntryOrder.php @@ -12,15 +12,13 @@ class UpdateCollectionEntryOrder implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable; - public function __construct(public $entryId, public $order) - { - } + public function __construct(public $entryId, public $entryOrder) {} public function handle() { if ($entry = Entry::find($this->entryId)) { - if ($this->order) { - $entry->order($this->order); + if ($this->entryOrder) { + $entry->order($this->entryOrder); } $entry->save(); From d9b11cb21f2e9ca03b248be971257bc1280a6210 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 09:13:41 +0000 Subject: [PATCH 3/6] method isnt a setter --- src/Jobs/UpdateCollectionEntryOrder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jobs/UpdateCollectionEntryOrder.php b/src/Jobs/UpdateCollectionEntryOrder.php index 5e08ed26..4e25ba24 100644 --- a/src/Jobs/UpdateCollectionEntryOrder.php +++ b/src/Jobs/UpdateCollectionEntryOrder.php @@ -18,7 +18,7 @@ public function handle() { if ($entry = Entry::find($this->entryId)) { if ($this->entryOrder) { - $entry->order($this->entryOrder); + $entry->set('order', $this->entryOrder); } $entry->save(); From 48798e15f636edeb105dea9a8ad8eb36f8a94e48 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 09:17:18 +0000 Subject: [PATCH 4/6] ensure order is added to data when present --- src/Entries/Entry.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index 54d6aaf6..a2da56c3 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -21,6 +21,10 @@ public static function fromModel(Model $model) $data[$key] = $model->$key; } + if ($model->order) { + $data['order'] = $model->order; + } + $entry = (new static) ->origin($model->origin_id) ->locale($model->site) From e6dec98cd822b8927f34a2c3ea09e72974e596e3 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 10:00:31 +0000 Subject: [PATCH 5/6] Use order in sequence --- src/Entries/EntryRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entries/EntryRepository.php b/src/Entries/EntryRepository.php index 85e25a7c..bbe5b9ab 100644 --- a/src/Entries/EntryRepository.php +++ b/src/Entries/EntryRepository.php @@ -85,8 +85,8 @@ public function updateOrders($collection, $ids = null) $collection->queryEntries() ->when($ids, fn ($query) => $query->whereIn('id', $ids)) ->get(['id']) - ->each(function ($entry) { - $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id(), $entry->order()); + ->each(function ($entry, $index) { + $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id(), $index + 1); $connection = config('statamic.eloquent-driver.collections.update_entry_order_connection', 'default'); From 588a8e2e696b2655ffea9ea776a40c813f82c743 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 13 Nov 2024 10:21:17 +0000 Subject: [PATCH 6/6] Revert --- src/Entries/EntryRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entries/EntryRepository.php b/src/Entries/EntryRepository.php index bbe5b9ab..85e25a7c 100644 --- a/src/Entries/EntryRepository.php +++ b/src/Entries/EntryRepository.php @@ -85,8 +85,8 @@ public function updateOrders($collection, $ids = null) $collection->queryEntries() ->when($ids, fn ($query) => $query->whereIn('id', $ids)) ->get(['id']) - ->each(function ($entry, $index) { - $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id(), $index + 1); + ->each(function ($entry) { + $dispatch = UpdateCollectionEntryOrder::dispatch($entry->id(), $entry->order()); $connection = config('statamic.eloquent-driver.collections.update_entry_order_connection', 'default');