Update DeleteAccountPipeline

This commit is contained in:
Daniel Supernault 2019-03-19 20:54:56 -06:00
parent 2b76db6421
commit 2378376595
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -30,6 +30,7 @@ use App\{
StatusHashtag, StatusHashtag,
Status, Status,
User, User,
UserDevice,
UserFilter, UserFilter,
UserSetting, UserSetting,
}; };
@ -66,7 +67,9 @@ class DeleteAccountPipeline implements ShouldQueue
} }
} }
}); });
});
DB::transaction(function() use ($user) {
if($user->profile) { if($user->profile) {
$avatar = $user->profile->avatar; $avatar = $user->profile->avatar;
@ -90,7 +93,9 @@ class DeleteAccountPipeline implements ShouldQueue
Follower::whereProfileId($id)->orWhere('following_id', $id)->forceDelete(); Follower::whereProfileId($id)->orWhere('following_id', $id)->forceDelete();
Like::whereProfileId($id)->forceDelete(); Like::whereProfileId($id)->forceDelete();
});
DB::transaction(function() use ($user) {
$medias = Media::whereUserId($user->id)->get(); $medias = Media::whereUserId($user->id)->get();
foreach($medias as $media) { foreach($medias as $media) {
$path = $media->media_path; $path = $media->media_path;
@ -103,31 +108,52 @@ class DeleteAccountPipeline implements ShouldQueue
} }
$media->forceDelete(); $media->forceDelete();
} }
});
DB::transaction(function() use ($user) {
Mention::whereProfileId($user->profile->id)->forceDelete(); Mention::whereProfileId($user->profile->id)->forceDelete();
Notification::whereProfileId($user->profile->id)->orWhere('actor_id', $user->profile->id)->forceDelete();
});
Notification::whereProfileId($id)->orWhere('actor_id', $id)->forceDelete(); DB::transaction(function() use ($user) {
Status::whereProfileId($user->profile->id)->forceDelete(); Status::whereProfileId($user->profile->id)->forceDelete();
Report::whereUserId($user->id)->forceDelete(); Report::whereUserId($user->id)->forceDelete();
$this->deleteProfile($user); $this->deleteProfile($user);
}); });
} }
public function deleteProfile($user) { protected function deleteProfile($user) {
DB::transaction(function() use ($user) { DB::transaction(function() use ($user) {
Profile::whereUserId($user->id)->delete(); Profile::whereUserId($user->id)->delete();
$this->deleteUser($user); $this->deleteUserSettings($user);
}); });
} }
public function deleteUser($user) { protected function deleteUserSettings($user) {
DB::transaction(function() use ($user) { DB::transaction(function() use ($user) {
UserDevice::whereUserId($user->id)->forceDelete();
UserFilter::whereUserId($user->id)->forceDelete(); UserFilter::whereUserId($user->id)->forceDelete();
UserSetting::whereUserId($user->id)->forceDelete(); UserSetting::whereUserId($user->id)->forceDelete();
$user->forceDelete(); $this->deleteUserColumns($user);
}); });
} }
protected function deleteUserColumns($user)
{
DB::transaction(function() use ($user) {
$user->status = 'deleted';
$user->name = 'deleted';
$user->email = $user->id;
$user->password = '';
$user->remember_token = null;
$user->is_admin = false;
$user->{'2fa_enabled'} = false;
$user->{'2fa_secret'} = null;
$user->{'2fa_backup_codes'} = null;
$user->{'2fa_setup_at'} = null;
$user->save();
});
}
} }