DeleteRemoteProfilePipeline.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. use App\Jobs\StatusPipeline\RemoteStatusDelete;
  53. class DeleteRemoteProfilePipeline implements ShouldQueue
  54. {
  55. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  56. protected $profile;
  57. public $timeout = 900;
  58. public $tries = 3;
  59. public $maxExceptions = 1;
  60. public $deleteWhenMissingModels = true;
  61. public function __construct(Profile $profile)
  62. {
  63. $this->profile = $profile;
  64. }
  65. public function handle()
  66. {
  67. $profile = $this->profile;
  68. $pid = $profile->id;
  69. if($profile->domain == null || $profile->private_key) {
  70. return;
  71. }
  72. $profile->status = 'delete';
  73. $profile->save();
  74. AccountService::del($pid);
  75. // Delete statuses
  76. Status::whereProfileId($pid)
  77. ->chunk(50, function($statuses) {
  78. foreach($statuses as $status) {
  79. RemoteStatusDelete::dispatch($status)->onQueue('delete');
  80. }
  81. });
  82. // Delete Poll Votes
  83. PollVote::whereProfileId($pid)->delete();
  84. // Delete Polls
  85. Poll::whereProfileId($pid)->delete();
  86. // Delete Avatar
  87. $profile->avatar->forceDelete();
  88. // Delete media tags
  89. MediaTag::whereProfileId($pid)->delete();
  90. // Delete DMs
  91. DirectMessage::whereFromId($pid)->orWhere('to_id', $pid)->delete();
  92. Conversation::whereFromId($pid)->orWhere('to_id', $pid)->delete();
  93. // Delete FollowRequests
  94. FollowRequest::whereFollowingId($pid)
  95. ->orWhere('follower_id', $pid)
  96. ->delete();
  97. // Delete relationships
  98. Follower::whereProfileId($pid)
  99. ->orWhere('following_id', $pid)
  100. ->delete();
  101. // Delete likes
  102. Like::whereProfileId($pid)->forceDelete();
  103. // Delete Story Views + Stories
  104. StoryView::whereProfileId($pid)->delete();
  105. $stories = Story::whereProfileId($pid)->get();
  106. foreach($stories as $story) {
  107. $path = storage_path('app/'.$story->path);
  108. if(is_file($path)) {
  109. unlink($path);
  110. }
  111. $story->forceDelete();
  112. }
  113. // Delete mutes/blocks
  114. UserFilter::whereFilterableType('App\Profile')->whereFilterableId($pid)->delete();
  115. // Delete mentions
  116. Mention::whereProfileId($pid)->forceDelete();
  117. // Delete notifications
  118. Notification::whereProfileId($pid)
  119. ->orWhere('actor_id', $pid)
  120. ->chunk(50, function($notifications) {
  121. foreach($notifications as $n) {
  122. $n->forceDelete();
  123. }
  124. });
  125. // Delete reports
  126. Report::whereProfileId($profile->id)->orWhere('reported_profile_id')->forceDelete();
  127. // Delete profile
  128. Profile::findOrFail($profile->id)->delete();
  129. return 1;
  130. }
  131. }