← All changes
|
app/Hooks/Handlers/CleanupHandlers/BookingCleaner.php
+20
-7
1.5.21
→
2.5.0
View file →
| @@ -1,12 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentBooking\App\Hooks\Handlers\CleanupHandlers; |
| 4 | 4 | |
| 5 | -use FluentBooking\App\Models\Booking; | |
| 6 | -use FluentBooking\App\Models\BookingActivity; | |
| 7 | 5 | use FluentBooking\App\Models\BookingHost; |
| 8 | -use FluentBooking\App\Models\BookingMeta; | |
| 9 | 6 | |
| 10 | 7 | class BookingCleaner |
| 11 | 8 | { |
| 12 | 9 | public function register() |
| @@ -26,12 +23,28 @@ | ||
| 26 | 23 | $order = \FluentBookingPro\App\Models\Order::query() |
| 27 | 24 | ->where('parent_id', $booking->id) |
| 28 | 25 | ->first(); |
| 29 | 26 | |
| 30 | - if ($order) { | |
| 31 | - do_action('fluent_booking/before_delete_order', $order, $booking); | |
| 32 | - $order->delete(); | |
| 33 | - do_action('fluent_booking/after_delete_order', $order, $booking); | |
| 27 | + if (!$order) { | |
| 28 | + return; | |
| 34 | 29 | } |
| 30 | + | |
| 31 | + if ($order->items) { | |
| 32 | + $order->items()->delete(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + if ($order->discounts) { | |
| 36 | + $order->discounts()->delete(); | |
| 37 | + } | |
| 38 | + | |
| 39 | + if ($order->transaction) { | |
| 40 | + $order->transaction()->delete(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + do_action('fluent_booking/before_delete_order', $order, $booking); | |
| 44 | + | |
| 45 | + $order->delete(); | |
| 46 | + | |
| 47 | + do_action('fluent_booking/after_delete_order', $order, $booking); | |
| 35 | 48 | } |
| 36 | 49 | } |
| 37 | 50 | } |