diff --git a/app/Jobs/DeletePipeline/DeleteRemoteProfilePipeline.php b/app/Jobs/DeletePipeline/DeleteRemoteProfilePipeline.php new file mode 100644 index 000000000..5c3cb3fe6 --- /dev/null +++ b/app/Jobs/DeletePipeline/DeleteRemoteProfilePipeline.php @@ -0,0 +1,140 @@ +profile = $profile; + } + + public function handle() + { + $profile = $this->profile; + + if($profile->domain == null || $profile->private_key) { + return; + } + + DB::transaction(function() use ($profile) { + $profile->avatar->forceDelete(); + + $id = $profile->id; + + MediaTag::whereProfileId($id)->delete(); + StatusHashtag::whereProfileId($id)->delete(); + DirectMessage::whereFromId($id)->delete(); + FollowRequest::whereFollowingId($id) + ->orWhere('follower_id', $id) + ->forceDelete(); + Follower::whereProfileId($id) + ->orWhere('following_id', $id) + ->forceDelete(); + Like::whereProfileId($id)->forceDelete(); + }); + + DB::transaction(function() use ($profile) { + $pid = $profile->id; + StoryView::whereProfileId($pid)->delete(); + $stories = Story::whereProfileId($pid)->get(); + foreach($stories as $story) { + $path = storage_path('app/'.$story->path); + if(is_file($path)) { + unlink($path); + } + $story->forceDelete(); + } + }); + + DB::transaction(function() use ($profile) { + $medias = Media::whereProfileId($profile->id)->get(); + foreach($medias as $media) { + $path = storage_path('app/'.$media->media_path); + $thumb = storage_path('app/'.$media->thumbnail_path); + if(is_file($path)) { + unlink($path); + } + if(is_file($thumb)) { + unlink($thumb); + } + $media->forceDelete(); + } + }); + + DB::transaction(function() use ($profile) { + Mention::whereProfileId($profile->id)->forceDelete(); + Notification::whereProfileId($profile->id) + ->orWhere('actor_id', $profile->id) + ->forceDelete(); + }); + + DB::transaction(function() use ($profile) { + Status::whereProfileId($profile->id) + ->cursor() + ->each(function($status) { + AccountInterstitial::where('item_type', 'App\Status') + ->where('item_id', $status->id) + ->delete(); + $status->forceDelete(); + }); + Report::whereProfileId($profile->id)->forceDelete(); + $this->deleteProfile($profile); + }); + } + + protected function deleteProfile($profile) { + DB::transaction(function() use ($profile) { + Profile::findOrFail($profile->id)->delete(); + }); + } +} diff --git a/app/Services/AdminStatsService.php b/app/Services/AdminStatsService.php index 367157be4..4198550ee 100644 --- a/app/Services/AdminStatsService.php +++ b/app/Services/AdminStatsService.php @@ -41,7 +41,7 @@ class AdminStatsService return Cache::remember('admin:dashboard:home:data:v0:24hr', now()->addHours(24), function() use ($day) { return [ 'failedjobs' => PrettyNumber::convert(FailedJob::where('failed_at', '>=', \Carbon\Carbon::now()->subDay())->count()), - 'statuses' => PrettyNumber::convert(Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count()), + 'statuses' => PrettyNumber::convert(Status::count()), 'profiles' => PrettyNumber::convert(Profile::count()), 'users' => PrettyNumber::convert(User::count()), 'instances' => PrettyNumber::convert(Instance::count()), diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 4c47b4af6..58ac45d64 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -21,6 +21,7 @@ use App\Util\ActivityPub\Helpers; use Illuminate\Support\Str; use App\Jobs\LikePipeline\LikePipeline; use App\Jobs\FollowPipeline\FollowPipeline; +use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; use App\Util\ActivityPub\Validator\Accept as AcceptValidator; use App\Util\ActivityPub\Validator\Add as AddValidator; @@ -470,15 +471,7 @@ class Inbox if(!$profile || $profile->private_key != null) { return; } - Notification::whereActorId($profile->id)->delete(); - $profile->avatar()->delete(); - $profile->followers()->delete(); - $profile->following()->delete(); - $profile->likes()->delete(); - $profile->media()->delete(); - $profile->hashtags()->delete(); - $profile->statuses()->delete(); - $profile->delete(); + DeleteRemoteProfilePipeline::dispatchNow($profile); return; } else { $type = $this->payload['object']['type']; @@ -496,16 +489,8 @@ class Inbox if(!$profile || $profile->private_key != null) { return; } - Notification::whereActorId($profile->id)->delete(); - $profile->avatar()->delete(); - $profile->followers()->delete(); - $profile->following()->delete(); - $profile->likes()->delete(); - $profile->media()->delete(); - $profile->hashtags()->delete(); - $profile->statuses()->delete(); - $profile->delete(); - return; + DeleteRemoteProfilePipeline::dispatchNow($profile); + return; break; case 'Tombstone':