2024_10_15_044935_create_moderated_profiles_table.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. use App\Profile;
  6. use App\ModLog;
  7. use App\Models\ModeratedProfile;
  8. return new class extends Migration
  9. {
  10. /**
  11. * Run the migrations.
  12. */
  13. public function up(): void
  14. {
  15. Schema::create('moderated_profiles', function (Blueprint $table) {
  16. $table->id();
  17. $table->string('profile_url')->unique()->nullable()->index();
  18. $table->unsignedBigInteger('profile_id')->unique()->nullable();
  19. $table->string('domain')->nullable();
  20. $table->text('note')->nullable();
  21. $table->boolean('is_banned')->default(false);
  22. $table->boolean('is_nsfw')->default(false);
  23. $table->boolean('is_unlisted')->default(false);
  24. $table->boolean('is_noautolink')->default(false);
  25. $table->boolean('is_nodms')->default(false);
  26. $table->boolean('is_notrending')->default(false);
  27. $table->timestamps();
  28. });
  29. $logs = ModLog::whereObjectType('App\Profile::class')->whereAction('admin.user.delete')->get();
  30. foreach($logs as $log) {
  31. $profile = Profile::withTrashed()->find($log->object_id);
  32. if(!$profile || $profile->private_key) {
  33. continue;
  34. }
  35. ModeratedProfile::updateOrCreate([
  36. 'profile_url' => $profile->remote_url,
  37. 'profile_id' => $profile->id,
  38. ], [
  39. 'is_banned' => true,
  40. 'domain' => $profile->domain,
  41. ]);
  42. }
  43. }
  44. /**
  45. * Reverse the migrations.
  46. */
  47. public function down(): void
  48. {
  49. Schema::dropIfExists('moderated_profiles');
  50. }
  51. };