NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Jobs; |
||
| 4 | |||
| 5 | use App\Models\User; |
||
| 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 | |||
| 12 | class RemoveInactiveAccounts implements ShouldQueue |
||
| 13 | { |
||
| 14 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * Create a new job instance. |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function __construct() |
||
| 22 | { |
||
| 23 | // |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Execute the job. |
||
| 28 | */ |
||
| 29 | public function handle(): void |
||
| 30 | { |
||
| 31 | $purgeDays = (int) config('nntmux.purge_inactive_users_days'); |
||
| 32 | $threshold = now()->subDays($purgeDays); |
||
| 33 | |||
| 34 | User::query()->where('roles_id', 1)->where(function ($q) use ($threshold) { |
||
| 35 | $q->where(function ($qq) use ($threshold) { |
||
| 36 | $qq->whereNotNull('lastlogin')->where('lastlogin', '<', $threshold); |
||
| 37 | })->orWhere(function ($qq) use ($threshold) { |
||
| 38 | // Only treat null lastlogin as inactive if the account is older than threshold |
||
| 39 | $qq->whereNull('lastlogin')->where('created_at', '<', $threshold); |
||
| 40 | }); |
||
| 41 | })->where(function ($q) use ($threshold) { |
||
| 42 | $q->where(function ($qq) use ($threshold) { |
||
| 43 | $qq->whereNotNull('apiaccess')->where('apiaccess', '<', $threshold); |
||
| 44 | })->orWhere(function ($qq) use ($threshold) { |
||
| 45 | $qq->whereNull('apiaccess')->where('created_at', '<', $threshold); |
||
| 46 | }); |
||
| 47 | }); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |