DeleteRemoteProfilePipeline.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace App\Jobs\DeletePipeline;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Queue\SerializesModels;
  5. use Illuminate\Queue\InteractsWithQueue;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use DB;
  9. use Illuminate\Support\Str;
  10. use App\{
  11. AccountInterstitial,
  12. AccountLog,
  13. Activity,
  14. Avatar,
  15. Bookmark,
  16. Collection,
  17. CollectionItem,
  18. Contact,
  19. DirectMessage,
  20. EmailVerification,
  21. Follower,
  22. FollowRequest,
  23. Hashtag,
  24. HashtagFollow,
  25. ImportData,
  26. ImportJob,
  27. Like,
  28. Media,
  29. MediaTag,
  30. Mention,
  31. Notification,
  32. OauthClient,
  33. Profile,
  34. ProfileSponsor,
  35. Report,
  36. ReportComment,
  37. ReportLog,
  38. StatusHashtag,
  39. Status,
  40. StatusView,
  41. Story,
  42. StoryView,
  43. User,
  44. UserDevice,
  45. UserFilter,
  46. UserSetting,
  47. };
  48. use App\Models\Conversation;
  49. use App\Models\Poll;
  50. use App\Models\PollVote;
  51. use App\Services\AccountService;
  52. class DeleteRemoteProfilePipeline implements ShouldQueue
  53. {
  54. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  55. protected $profile;
  56. public $timeout = 900;
  57. public $tries = 3;
  58. public $maxExceptions = 1;
  59. public $deleteWhenMissingModels = true;
  60. public function __construct(Profile $profile)
  61. {
  62. $this->profile = $profile;
  63. }
  64. public function handle()
  65. {
  66. $profile = $this->profile;
  67. $pid = $profile->id;
  68. if($profile->domain == null || $profile->private_key) {
  69. return;
  70. }
  71. $profile->status = 'delete';
  72. $profile->save();
  73. AccountService::del($pid);
  74. // Delete statuses
  75. Status::whereProfileId($pid)
  76. ->chunk(50, function($statuses) {
  77. foreach($statuses as $status) {
  78. DeleteRemoteStatusPipeline::dispatch($status)->onQueue('delete');
  79. }
  80. });
  81. // Delete Poll Votes
  82. PollVote::whereProfileId($pid)->delete();
  83. // Delete Polls
  84. Poll::whereProfileId($pid)->delete();
  85. // Delete Avatar
  86. $profile->avatar->forceDelete();
  87. // Delete media tags
  88. MediaTag::whereProfileId($pid)->delete();
  89. // Delete DMs
  90. DirectMessage::whereFromId($pid)->orWhere('to_id', $pid)->delete();
  91. Conversation::whereFromId($pid)->orWhere('to_id', $pid)->delete();
  92. // Delete FollowRequests
  93. FollowRequest::whereFollowingId($pid)
  94. ->orWhere('follower_id', $pid)
  95. ->delete();
  96. // Delete relationships
  97. Follower::whereProfileId($pid)
  98. ->orWhere('following_id', $pid)
  99. ->delete();
  100. // Delete likes
  101. Like::whereProfileId($pid)->forceDelete();
  102. // Delete Story Views + Stories
  103. StoryView::whereProfileId($pid)->delete();
  104. $stories = Story::whereProfileId($pid)->get();
  105. foreach($stories as $story) {
  106. $path = storage_path('app/'.$story->path);
  107. if(is_file($path)) {
  108. unlink($path);
  109. }
  110. $story->forceDelete();
  111. }
  112. // Delete mutes/blocks
  113. UserFilter::whereFilterableType('App\Profile')->whereFilterableId($pid)->delete();
  114. // Delete mentions
  115. Mention::whereProfileId($pid)->forceDelete();
  116. // Delete notifications
  117. Notification::whereProfileId($pid)
  118. ->orWhere('actor_id', $pid)
  119. ->chunk(50, function($notifications) {
  120. foreach($notifications as $n) {
  121. $n->forceDelete();
  122. }
  123. });
  124. // Delete reports
  125. Report::whereProfileId($profile->id)->orWhere('reported_profile_id')->forceDelete();
  126. // Delete profile
  127. Profile::findOrFail($profile->id)->delete();
  128. return 1;
  129. }
  130. }