HandleSpammerPipeline.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs\ModPipeline;
  3. use Cache;
  4. use App\Profile;
  5. use App\Status;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. use App\Services\StatusService;
  12. class HandleSpammerPipeline implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. protected $profile;
  16. public $deleteWhenMissingModels = true;
  17. public function __construct(Profile $profile)
  18. {
  19. $this->profile = $profile;
  20. }
  21. public function handle()
  22. {
  23. $profile = $this->profile;
  24. $profile->unlisted = true;
  25. $profile->cw = true;
  26. $profile->no_autolink = true;
  27. $profile->save();
  28. Status::whereProfileId($profile->id)
  29. ->chunk(50, function($statuses) {
  30. foreach($statuses as $status) {
  31. $status->is_nsfw = true;
  32. $status->scope = $status->scope === 'public' ? 'unlisted' : $status->scope;
  33. $status->visibility = $status->scope;
  34. $status->save();
  35. StatusService::del($status->id);
  36. }
  37. });
  38. Cache::forget('_api:statuses:recent_9:'.$profile->id);
  39. return 1;
  40. }
  41. }