2018-11-26 19:33:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\DeletePipeline;
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2018-12-21 06:15:20 +00:00
|
|
|
use DB;
|
2022-03-31 03:44:44 +00:00
|
|
|
use Storage;
|
2019-04-22 05:38:34 +00:00
|
|
|
use Illuminate\Support\Str;
|
2022-03-31 04:35:17 +00:00
|
|
|
use App\Services\AccountService;
|
2022-12-05 12:27:27 +00:00
|
|
|
use App\Services\FollowerService;
|
2022-03-31 04:35:17 +00:00
|
|
|
use App\Services\PublicTimelineService;
|
2018-11-26 19:33:56 +00:00
|
|
|
use App\{
|
2020-12-05 07:20:45 +00:00
|
|
|
AccountInterstitial,
|
2020-02-16 06:10:36 +00:00
|
|
|
AccountLog,
|
|
|
|
Avatar,
|
|
|
|
Bookmark,
|
|
|
|
Collection,
|
|
|
|
CollectionItem,
|
|
|
|
Contact,
|
|
|
|
DirectMessage,
|
|
|
|
EmailVerification,
|
|
|
|
Follower,
|
|
|
|
FollowRequest,
|
|
|
|
Hashtag,
|
|
|
|
HashtagFollow,
|
2020-12-14 09:58:07 +00:00
|
|
|
ImportData,
|
|
|
|
ImportJob,
|
2020-02-16 06:10:36 +00:00
|
|
|
Like,
|
|
|
|
Media,
|
2020-12-14 09:58:07 +00:00
|
|
|
MediaTag,
|
2020-02-16 06:10:36 +00:00
|
|
|
Mention,
|
|
|
|
Notification,
|
|
|
|
OauthClient,
|
|
|
|
Profile,
|
|
|
|
ProfileSponsor,
|
|
|
|
Report,
|
|
|
|
ReportComment,
|
|
|
|
ReportLog,
|
|
|
|
StatusHashtag,
|
2022-03-31 04:35:17 +00:00
|
|
|
StatusArchived,
|
2020-02-16 06:10:36 +00:00
|
|
|
Status,
|
|
|
|
Story,
|
|
|
|
StoryView,
|
|
|
|
User,
|
|
|
|
UserDevice,
|
|
|
|
UserFilter,
|
|
|
|
UserSetting,
|
2018-11-26 19:33:56 +00:00
|
|
|
};
|
2022-12-24 11:28:52 +00:00
|
|
|
use App\Models\Conversation;
|
|
|
|
use App\Models\Poll;
|
|
|
|
use App\Models\PollVote;
|
|
|
|
use App\Models\Portfolio;
|
2022-03-31 04:35:17 +00:00
|
|
|
use App\Models\UserPronoun;
|
2022-12-29 02:34:16 +00:00
|
|
|
use App\Jobs\StatusPipeline\StatusDelete;
|
2018-11-26 19:33:56 +00:00
|
|
|
|
|
|
|
class DeleteAccountPipeline implements ShouldQueue
|
|
|
|
{
|
2020-02-16 06:10:36 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $user;
|
|
|
|
|
2022-12-05 08:09:45 +00:00
|
|
|
public $timeout = 900;
|
2022-12-24 11:28:52 +00:00
|
|
|
public $tries = 3;
|
|
|
|
public $maxExceptions = 1;
|
|
|
|
public $deleteWhenMissingModels = true;
|
2022-12-05 08:09:45 +00:00
|
|
|
|
2020-02-16 06:10:36 +00:00
|
|
|
public function __construct(User $user)
|
|
|
|
{
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$user = $this->user;
|
2022-12-24 11:28:52 +00:00
|
|
|
$profile = $user->profile;
|
|
|
|
$id = $user->profile_id;
|
2022-03-31 03:44:44 +00:00
|
|
|
$this->deleteUserColumns($user);
|
2022-03-31 04:35:17 +00:00
|
|
|
AccountService::del($user->profile_id);
|
2020-02-16 06:10:36 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
AccountLog::whereItemType('App\User')->whereItemId($user->id)->forceDelete();
|
2020-02-16 06:10:36 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
AccountInterstitial::whereUserId($user->id)->delete();
|
2020-12-05 07:20:45 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
// Delete Avatar
|
|
|
|
$profile->avatar->forceDelete();
|
2022-03-31 04:35:17 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
// Delete Poll Votes
|
|
|
|
PollVote::whereProfileId($id)->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
// Delete Polls
|
|
|
|
Poll::whereProfileId($id)->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
// Delete Portfolio
|
|
|
|
Portfolio::whereProfileId($id)->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
ImportData::whereProfileId($id)
|
|
|
|
->cursor()
|
|
|
|
->each(function($data) {
|
|
|
|
$path = storage_path('app/'.$data->path);
|
2020-02-16 06:10:36 +00:00
|
|
|
if(is_file($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
2022-12-24 11:28:52 +00:00
|
|
|
$data->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
});
|
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
ImportJob::whereProfileId($id)
|
|
|
|
->cursor()
|
|
|
|
->each(function($data) {
|
|
|
|
$path = storage_path('app/'.$data->media_json);
|
|
|
|
if(is_file($path)) {
|
|
|
|
unlink($path);
|
2020-02-16 06:10:36 +00:00
|
|
|
}
|
2022-12-24 11:28:52 +00:00
|
|
|
$data->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
});
|
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
MediaTag::whereProfileId($id)->delete();
|
|
|
|
Bookmark::whereProfileId($id)->forceDelete();
|
|
|
|
EmailVerification::whereUserId($user->id)->forceDelete();
|
|
|
|
StatusHashtag::whereProfileId($id)->delete();
|
|
|
|
DirectMessage::whereFromId($id)->orWhere('to_id', $id)->delete();
|
|
|
|
Conversation::whereFromId($id)->orWhere('to_id', $id)->delete();
|
|
|
|
StatusArchived::whereProfileId($id)->delete();
|
|
|
|
UserPronoun::whereProfileId($id)->delete();
|
|
|
|
FollowRequest::whereFollowingId($id)
|
|
|
|
->orWhere('follower_id', $id)
|
|
|
|
->forceDelete();
|
|
|
|
Follower::whereProfileId($id)
|
|
|
|
->orWhere('following_id', $id)
|
|
|
|
->each(function($follow) {
|
|
|
|
FollowerService::remove($follow->profile_id, $follow->following_id);
|
|
|
|
$follow->delete();
|
|
|
|
});
|
|
|
|
FollowerService::delCache($id);
|
|
|
|
Like::whereProfileId($id)->forceDelete();
|
|
|
|
Mention::whereProfileId($id)->forceDelete();
|
|
|
|
|
|
|
|
StoryView::whereProfileId($id)->delete();
|
|
|
|
$stories = Story::whereProfileId($id)->get();
|
|
|
|
foreach($stories as $story) {
|
|
|
|
$path = storage_path('app/'.$story->path);
|
|
|
|
if(is_file($path)) {
|
|
|
|
unlink($path);
|
2020-02-16 06:10:36 +00:00
|
|
|
}
|
2022-12-24 11:28:52 +00:00
|
|
|
$story->forceDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserDevice::whereUserId($user->id)->forceDelete();
|
|
|
|
UserFilter::whereUserId($user->id)->forceDelete();
|
|
|
|
UserSetting::whereUserId($user->id)->forceDelete();
|
|
|
|
|
|
|
|
Mention::whereProfileId($id)->forceDelete();
|
|
|
|
Notification::whereProfileId($id)
|
|
|
|
->orWhere('actor_id', $id)
|
|
|
|
->forceDelete();
|
|
|
|
|
|
|
|
$collections = Collection::whereProfileId($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();
|
|
|
|
DB::table('oauth_access_tokens')->whereUserId($user->id)->delete();
|
|
|
|
DB::table('oauth_auth_codes')->whereUserId($user->id)->delete();
|
|
|
|
ProfileSponsor::whereProfileId($id)->delete();
|
|
|
|
|
|
|
|
Status::whereProfileId($id)->chunk(50, function($statuses) {
|
|
|
|
foreach($statuses as $status) {
|
|
|
|
StatusDelete::dispatch($status)->onQueue('high');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Report::whereUserId($user->id)->forceDelete();
|
|
|
|
PublicTimelineService::warmCache(true, 400);
|
|
|
|
Profile::whereUserId($user->id)->delete();
|
2020-02-16 06:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
2018-11-26 19:33:56 +00:00
|
|
|
}
|