Skip to content

Commit cf14b9b

Browse files
committed
fix return type
1 parent 7619abc commit cf14b9b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/Actions/Shop/OrderService.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use App\Models\User;
2020
use Illuminate\Database\Eloquent\Builder;
2121
use Illuminate\Support\Facades\Auth;
22+
use Illuminate\Support\Facades\DB;
2223
use Illuminate\Support\Str;
2324

2425
class OrderService
@@ -126,14 +127,19 @@ public function getAll(): array
126127
/**
127128
* Clear old orders that are older than 2 weeks, have no items, and have no user_id.
128129
*
129-
* @return int Number of orders deleted
130+
* @return void Number of orders deleted
130131
*/
131-
public function clearOldOrders(): int
132+
public function clearOldOrders(): void
132133
{
133-
// Delete all the order items first to avoid foreign key constraint issues
134-
OrderItem::whereIn('order_id', $this->getQueryOldOrders()->select('id'))->delete();
134+
DB::transaction(function (): void {
135+
// Delete all the order items first to avoid foreign key constraint issues
136+
$chunk = $this->getQueryOldOrders()->pluck('id')->chunk(100);
137+
foreach ($chunk as $old_orders_ids) {
138+
OrderItem::whereIn('order_id', $old_orders_ids)->delete();
139+
}
140+
$this->getQueryOldOrders()->delete();
141+
});
135142

136-
return $this->getQueryOldOrders()->delete();
137143
}
138144

139145
/**

0 commit comments

Comments
 (0)