| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Hooks\Handlers\CleanupHandlers; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Booking; |
| 6 |
use FluentBooking\App\Models\BookingActivity; |
| 7 |
use FluentBooking\App\Models\BookingHost; |
| 8 |
use FluentBooking\App\Models\BookingMeta; |
| 9 |
|
| 10 |
class BookingCleaner |
| 11 |
{ |
| 12 |
public function register() |
| 13 |
{ |
| 14 |
add_action('fluent_booking/before_delete_booking', [$this, 'handleBeforeDelete'], 10, 1); |
| 15 |
} |
| 16 |
|
| 17 |
public function handleBeforeDelete($booking) |
| 18 |
{ |
| 19 |
if (empty($booking)) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
BookingHost::query()->where('booking_id', $booking->id)->delete(); |
| 24 |
|
| 25 |
if (defined('FLUENT_BOOKING_PRO_DIR_FILE')) { |
| 26 |
$order = \FluentBookingPro\App\Models\Order::query() |
| 27 |
->where('parent_id', $booking->id) |
| 28 |
->first(); |
| 29 |
|
| 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); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|