Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/UserObserver.php
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | class UserObserver | ||||
public function deleting(User $user) | public function deleting(User $user) | ||||
{ | { | ||||
// TODO: Especially in tests we're doing delete() on a already deleted user. | // TODO: Especially in tests we're doing delete() on a already deleted user. | ||||
// Should we escape here - for performance reasons? | // Should we escape here - for performance reasons? | ||||
// TODO: I think all of this should use database transactions | // TODO: I think all of this should use database transactions | ||||
// Entitlements do not have referential integrity on the entitled object, so this is our | // Entitlements do not have referential integrity on the entitled object, so this is our | ||||
// way of doing an onDelete('cascade') without the foreign key. | // way of doing an onDelete('cascade') without the foreign key. | ||||
Entitlement::where('entitleable_id', $user->id) | $entitlements = Entitlement::where('entitleable_id', $user->id) | ||||
->where('entitleable_type', User::class) | ->where('entitleable_type', User::class)->get(); | ||||
->delete(); | |||||
foreach ($entitlements as $entitlement) { | |||||
$entitlement->delete(); | |||||
} | |||||
// Remove owned users/domains | // Remove owned users/domains | ||||
$wallets = $user->wallets()->pluck('id')->all(); | $wallets = $user->wallets()->pluck('id')->all(); | ||||
$assignments = Entitlement::whereIn('wallet_id', $wallets)->get(); | $assignments = Entitlement::whereIn('wallet_id', $wallets)->get(); | ||||
$users = []; | $users = []; | ||||
$domains = []; | $domains = []; | ||||
$entitlements = []; | $entitlements = []; | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |