From 0b3d2aabd5861c98831d5b45b9a3e6f6f57efdb2 Mon Sep 17 00:00:00 2001 From: Sabatino Masala Date: Thu, 15 Aug 2024 20:31:38 +0200 Subject: [PATCH] Run prepareNestedBatches on append/prependToChain & chain (#52486) * Run prepareNestedBatches on append/prependToChain * Cleanup leftover import * Update chain method * Update Queueable.php --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Bus/Queueable.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Bus/Queueable.php b/src/Illuminate/Bus/Queueable.php index 78dcac289b96..f4de59d6b7d2 100644 --- a/src/Illuminate/Bus/Queueable.php +++ b/src/Illuminate/Bus/Queueable.php @@ -197,7 +197,9 @@ public function through($middleware) */ public function chain($chain) { - $this->chained = collect($chain)->map(function ($job) { + $jobs = ChainedBatch::prepareNestedBatches(collect($chain)); + + $this->chained = $jobs->map(function ($job) { return $this->serializeJob($job); })->all(); @@ -212,7 +214,9 @@ public function chain($chain) */ public function prependToChain($job) { - $this->chained = Arr::prepend($this->chained, $this->serializeJob($job)); + $jobs = ChainedBatch::prepareNestedBatches(collect([$job])); + + $this->chained = Arr::prepend($this->chained, $this->serializeJob($jobs->first())); return $this; } @@ -225,7 +229,9 @@ public function prependToChain($job) */ public function appendToChain($job) { - $this->chained = array_merge($this->chained, [$this->serializeJob($job)]); + $jobs = ChainedBatch::prepareNestedBatches(collect([$job])); + + $this->chained = array_merge($this->chained, [$this->serializeJob($jobs->first())]); return $this; }