DeleteRemoteProfile.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
  4. use App\Profile;
  5. use Illuminate\Console\Command;
  6. use function Laravel\Prompts\confirm;
  7. use function Laravel\Prompts\search;
  8. class DeleteRemoteProfile extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'app:delete-remote-profile';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Delete remote profile';
  22. /**
  23. * Execute the console command.
  24. */
  25. public function handle()
  26. {
  27. $id = search(
  28. 'Search for the account',
  29. fn (string $value) => strlen($value) > 2
  30. ? Profile::whereNotNull('domain')->where('username', 'like', $value.'%')->pluck('username', 'id')->all()
  31. : []
  32. );
  33. $profile = Profile::whereNotNull('domain')->find($id);
  34. if (! $profile) {
  35. $this->error('Could not find profile.');
  36. exit;
  37. }
  38. $confirmed = confirm('Are you sure you want to delete '.$profile->username.'\'s account? This action cannot be reversed.');
  39. DeleteRemoteProfilePipeline::dispatch($profile)->onQueue('adelete');
  40. $this->info('Dispatched delete job, it may take a few minutes...');
  41. exit;
  42. }
  43. }