Просмотр файла app/Console/Commands/DeletePending.php

Размер файла: 1.32Kb
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use App\Models\User;
  6. use Illuminate\Console\Command;
  7.  
  8. class DeletePending extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'delete:pending';
  16.  
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'Delete pending user';
  23.  
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33.  
  34. /**
  35. * Удаляет не активированные аккаунты
  36. *
  37. * @return int
  38. */
  39. public function handle()
  40. {
  41. if (setting('regkeys')) {
  42. $users = User::query()
  43. ->where('level', User::PENDED)
  44. ->where('created_at', '<', strtotime('-1 day', SITETIME))
  45. ->get();
  46.  
  47. foreach ($users as $user) {
  48. $user->delete();
  49. }
  50. } else {
  51. User::query()
  52. ->where('level', User::PENDED)
  53. ->update([
  54. 'confirmregkey' => null,
  55. 'level' => User::USER,
  56. ]);
  57. }
  58.  
  59. $this->info('Pending user successfully deleted.');
  60.  
  61. return 0;
  62. }
  63. }