2023_01_19_141156_fix_bookmark_visibility.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. use App\Bookmark;
  6. use App\Status;
  7. use App\Services\FollowerService;
  8. return new class extends Migration
  9. {
  10. /**
  11. * Run the migrations.
  12. *
  13. * @return void
  14. */
  15. public function up()
  16. {
  17. Bookmark::chunk(200, function($bookmarks) {
  18. foreach($bookmarks as $bookmark) {
  19. $status = Status::find($bookmark->status_id);
  20. if(!$status) {
  21. $bookmark->delete();
  22. continue;
  23. }
  24. if(!in_array($status->visibility, ['public', 'unlisted', 'private'])) {
  25. $bookmark->delete();
  26. continue;
  27. }
  28. if(!in_array($status->visibility, ['public', 'unlisted'])) {
  29. if($bookmark->profile_id == $status->profile_id) {
  30. continue;
  31. } else {
  32. if(!FollowerService::follows($bookmark->profile_id, $status->profile_id)) {
  33. $bookmark->delete();
  34. }
  35. }
  36. }
  37. }
  38. });
  39. }
  40. /**
  41. * Reverse the migrations.
  42. *
  43. * @return void
  44. */
  45. public function down()
  46. {
  47. //
  48. }
  49. };