From 3c742ce3109398c7bdb8ded481bc4b1002de1dcf Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 14 May 2025 10:00:04 +0200 Subject: [PATCH] Update inactive users deletion handling --- .env.example | 1 + app/Jobs/RemoveInactiveAccounts.php | 13 +++++++++++-- config/nntmux.php | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index eb246e3b1..00089a3fb 100644 --- a/.env.example +++ b/.env.example @@ -195,6 +195,7 @@ HORIZON_PREFIX=horizon: POSTMARK_TOKEN= PURGE_INACTIVE_USERS=false +PURGE_INACTIVE_USERS_DAYS=180 OTP_ENABLED=false diff --git a/app/Jobs/RemoveInactiveAccounts.php b/app/Jobs/RemoveInactiveAccounts.php index 61222c8eb..1a3a84887 100644 --- a/app/Jobs/RemoveInactiveAccounts.php +++ b/app/Jobs/RemoveInactiveAccounts.php @@ -28,7 +28,16 @@ class RemoveInactiveAccounts implements ShouldQueue */ public function handle(): void { - User::query()->where('lastlogin', '<', now()->subMonths(6))->where('apiaccess', '<', now()->subMonths(6))->where('roles_id', '=', 1)->delete(); - User::query()->where('lastlogin', '<', now()->subMonths(6))->whereNull('apiaccess')->where('roles_id', '=', 1)->delete(); + $purgeDays = config('nntmux.purge_inactive_users_days'); + User::query()->where('roles_id', '=', 1) + ->where(function ($query) use ($purgeDays) { + $query->where('lastlogin', '<', now()->subDays($purgeDays)) + ->orWhereNull('lastlogin'); + }) + ->where(function ($query) use ($purgeDays) { + $query->where('apiaccess', '<', now()->subDays($purgeDays)) + ->orWhereNull('apiaccess'); + }) + ->delete(); } } diff --git a/config/nntmux.php b/config/nntmux.php index 83eb88e74..c1430e709 100644 --- a/config/nntmux.php +++ b/config/nntmux.php @@ -16,6 +16,7 @@ return [ 'admin_email' => env('ADMIN_EMAIL', 'admin@example.com'), 'multiprocessing_max_child_time' => env('NN_MULTIPROCESSING_MAX_CHILD_TIME', 1800), 'purge_inactive_users' => env('PURGE_INACTIVE_USERS', false), + 'purge_inactive_users_days' => env('PURGE_INACTIVE_USERS_DAYS', 180), 'elasticsearch_enabled' => env('ELASTICSEARCH_ENABLED', false), 'btcpay_webhook_secret' => env('BTCPAY_SECRET'), 'tmp_unrar_path' => env('TEMP_UNRAR_PATH', storage_path('tmp/unrar/')),