| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Hooks\Handlers\CleanupHandlers; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Booking; |
| 6 |
use FluentBooking\App\Models\BookingHost; |
| 7 |
use FluentBooking\App\Models\Calendar; |
| 8 |
use FluentBooking\App\Models\CalendarSlot; |
| 9 |
|
| 10 |
class UserCleaner |
| 11 |
{ |
| 12 |
public function register() |
| 13 |
{ |
| 14 |
add_action('delete_user', [$this, 'handleBeforeDelete'], 10, 2); |
| 15 |
} |
| 16 |
|
| 17 |
public function handleBeforeDelete($userId, $reassignId) |
| 18 |
{ |
| 19 |
return; |
| 20 |
if ($reassignId) { |
| 21 |
$assignable = [ |
| 22 |
Calendar::query(), |
| 23 |
CalendarSlot::query(), |
| 24 |
BookingHost::query() |
| 25 |
]; |
| 26 |
|
| 27 |
foreach ($assignable as $model) { |
| 28 |
$model::where('user_id', $reassignId)->update(['user_id' => $userId]); |
| 29 |
} |
| 30 |
return; |
| 31 |
} |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
} |