mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 13:33:18 +00:00
Merge pull request #2020 from pixelfed/staging
Update DeleteAccountPipeline, fixes #2016
This commit is contained in:
commit
6f96cafebd
3 changed files with 169 additions and 143 deletions
|
@ -13,7 +13,7 @@ class UserDelete extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:delete {id}';
|
||||
protected $signature = 'user:delete {id} {--force}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -40,12 +40,24 @@ class UserDelete extends Command
|
|||
public function handle()
|
||||
{
|
||||
$id = $this->argument('id');
|
||||
$user = User::whereUsername($id)->orWhere('id', $id)->first();
|
||||
$force = $this->option('force');
|
||||
|
||||
if(ctype_digit($id) == true) {
|
||||
$user = User::find($id);
|
||||
} else {
|
||||
$user = User::whereUsername($id)->first();
|
||||
}
|
||||
|
||||
if(!$user) {
|
||||
$this->error('Could not find any user with that username or id.');
|
||||
exit;
|
||||
}
|
||||
|
||||
if($user->status == 'deleted' && $force == false) {
|
||||
$this->error('Account has already been deleted.');
|
||||
return;
|
||||
}
|
||||
|
||||
if($user->is_admin == true) {
|
||||
$this->error('Cannot delete an admin account from CLI.');
|
||||
exit;
|
||||
|
@ -62,10 +74,12 @@ class UserDelete extends Command
|
|||
exit;
|
||||
}
|
||||
|
||||
if($user->status !== 'deleted') {
|
||||
$profile = $user->profile;
|
||||
$profile->status = $user->status = 'deleted';
|
||||
$profile->save();
|
||||
$user->save();
|
||||
}
|
||||
|
||||
DeleteAccountPipeline::dispatch($user)->onQueue('high');
|
||||
}
|
||||
|
|
|
@ -15,16 +15,21 @@ use App\{
|
|||
Avatar,
|
||||
Bookmark,
|
||||
Collection,
|
||||
CollectionItem,
|
||||
Contact,
|
||||
DirectMessage,
|
||||
EmailVerification,
|
||||
Follower,
|
||||
FollowRequest,
|
||||
Hashtag,
|
||||
HashtagFollow,
|
||||
Like,
|
||||
Media,
|
||||
Mention,
|
||||
Notification,
|
||||
OauthClient,
|
||||
Profile,
|
||||
ProfileSponsor,
|
||||
Report,
|
||||
ReportComment,
|
||||
ReportLog,
|
||||
|
@ -44,24 +49,15 @@ class DeleteAccountPipeline implements ShouldQueue
|
|||
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = $this->user;
|
||||
|
||||
DB::transaction(function() use ($user) {
|
||||
AccountLog::chunk(200, function($logs) use ($user) {
|
||||
foreach($logs as $log) {
|
||||
|
@ -75,21 +71,20 @@ class DeleteAccountPipeline implements ShouldQueue
|
|||
DB::transaction(function() use ($user) {
|
||||
if($user->profile) {
|
||||
$avatar = $user->profile->avatar;
|
||||
|
||||
$avatar->forceDelete();
|
||||
}
|
||||
|
||||
Bookmark::whereProfileId($user->profile->id)->forceDelete();
|
||||
$id = $user->profile_id;
|
||||
|
||||
Bookmark::whereProfileId($user->profile_id)->forceDelete();
|
||||
EmailVerification::whereUserId($user->id)->forceDelete();
|
||||
$id = $user->profile->id;
|
||||
|
||||
StatusHashtag::whereProfileId($id)->delete();
|
||||
|
||||
FollowRequest::whereFollowingId($id)->orWhere('follower_id', $id)->forceDelete();
|
||||
|
||||
Follower::whereProfileId($id)->orWhere('following_id', $id)->forceDelete();
|
||||
|
||||
FollowRequest::whereFollowingId($id)
|
||||
->orWhere('follower_id', $id)
|
||||
->forceDelete();
|
||||
Follower::whereProfileId($id)
|
||||
->orWhere('following_id', $id)
|
||||
->forceDelete();
|
||||
Like::whereProfileId($id)->forceDelete();
|
||||
});
|
||||
|
||||
|
@ -123,12 +118,26 @@ class DeleteAccountPipeline implements ShouldQueue
|
|||
});
|
||||
|
||||
DB::transaction(function() use ($user) {
|
||||
Mention::whereProfileId($user->profile->id)->forceDelete();
|
||||
Notification::whereProfileId($user->profile->id)->orWhere('actor_id', $user->profile->id)->forceDelete();
|
||||
Mention::whereProfileId($user->profile_id)->forceDelete();
|
||||
Notification::whereProfileId($user->profile_id)
|
||||
->orWhere('actor_id', $user->profile_id)
|
||||
->forceDelete();
|
||||
});
|
||||
|
||||
DB::transaction(function() use ($user) {
|
||||
Status::whereProfileId($user->profile->id)->forceDelete();
|
||||
$collections = Collection::whereProfileId($user->profile_id)->get();
|
||||
foreach ($collections as $collection) {
|
||||
$collection->items()->delete();
|
||||
$collection->delete();
|
||||
}
|
||||
Contact::whereUserId($user->id)->delete();
|
||||
HashtagFollow::whereUserId($user->id)->delete();
|
||||
OauthClient::whereUserId($user->id)->delete();
|
||||
ProfileSponsor::whereProfileId($user->profile_id)->delete();
|
||||
});
|
||||
|
||||
DB::transaction(function() use ($user) {
|
||||
Status::whereProfileId($user->profile_id)->forceDelete();
|
||||
Report::whereUserId($user->id)->forceDelete();
|
||||
$this->deleteProfile($user);
|
||||
});
|
||||
|
@ -166,6 +175,5 @@ class DeleteAccountPipeline implements ShouldQueue
|
|||
$user->{'2fa_setup_at'} = null;
|
||||
$user->save();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ class UserObserver
|
|||
*/
|
||||
public function saved(User $user)
|
||||
{
|
||||
if($user->status == 'deleted') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($user->profile)) {
|
||||
$profile = DB::transaction(function() use($user) {
|
||||
$profile = new Profile();
|
||||
|
|
Loading…
Reference in a new issue