From 55bd9a7037e55beca4a200bee8e0239c18253b09 Mon Sep 17 00:00:00 2001 From: Anthony Plunkett Date: Tue, 27 May 2025 16:09:37 -0400 Subject: [PATCH 1/3] show joined date based on database (was static) --- resources/views/members/partials/info.blade.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/resources/views/members/partials/info.blade.php b/resources/views/members/partials/info.blade.php index 14ae80e4..9d043045 100644 --- a/resources/views/members/partials/info.blade.php +++ b/resources/views/members/partials/info.blade.php @@ -1,13 +1,10 @@

{{ trans('Info') }}

- - - - - {{-- TODO: Link to archive page --}} - - - -
Joined:June 18, 2017
+
+
+
Joined
+
+ +
From 374afbcdf388de4717e873917aebeea1504926bd Mon Sep 17 00:00:00 2001 From: Anthony Plunkett Date: Tue, 27 May 2025 16:12:42 -0400 Subject: [PATCH 2/3] add query to find stale users could move the current 24hr window to a .env variable. --- app/Repositories/UserRepository.php | 14 ++++++++++++++ app/Repositories/UserRepositoryInterface.php | 4 ++++ app/Services/UserService.php | 13 +++++++++++++ 3 files changed, 31 insertions(+) diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index ec11b419..d3962ec6 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -6,6 +6,10 @@ use App\Dtos\UserDto; use App\Models\User; +use App\Enums\UserStateEnum; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Collection; + final class UserRepository extends BaseRepository implements UserRepositoryInterface { @@ -31,4 +35,14 @@ public function updateState(User $user, string $state): void $user->save(); } + + public function findStaleUsers(): Collection + { + return User::query() + ->where('state', UserStateEnum::Pending->value) + ->whereNull('email_verified_at') + ->whereNull('pm_type') + ->where('updated_at', '<', Carbon::now()->subHours(24)) + ->get(); + } } diff --git a/app/Repositories/UserRepositoryInterface.php b/app/Repositories/UserRepositoryInterface.php index d401f549..9ac6b6d5 100644 --- a/app/Repositories/UserRepositoryInterface.php +++ b/app/Repositories/UserRepositoryInterface.php @@ -6,10 +6,14 @@ use App\Dtos\UserDto; use App\Models\User; +use Illuminate\Database\Eloquent\Collection; + interface UserRepositoryInterface extends BaseRepositoryInterface { public function createUser(UserDto $dto); public function updateState(User $user, string $state); + + public function findStaleUsers(): Collection; } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index c08a162c..8d24ee04 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -9,6 +9,8 @@ use App\Repositories\UserRepositoryInterface; use App\Traits\LoggingTrait; use Exception; +use Illuminate\Database\Eloquent\Collection; + final class UserService { @@ -41,4 +43,15 @@ public function update(int $userId, array $data): ?User { return $this->userRepository->update($userId, $data); } + + public function getStaleUsers(): Collection + { + try { + return $this->userRepository->findStaleUsers(); + } catch (Exception $exception) { + $this->logError($exception); + + return collect(); + } + } } From 7cc05cc3c40d64db24c48d1c37449c032e1eeb9b Mon Sep 17 00:00:00 2001 From: Anthony Plunkett Date: Tue, 27 May 2025 16:13:00 -0400 Subject: [PATCH 3/3] add console command to prune stale users --- app/Console/Commands/DeleteStaleUsers.php | 85 +++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 app/Console/Commands/DeleteStaleUsers.php diff --git a/app/Console/Commands/DeleteStaleUsers.php b/app/Console/Commands/DeleteStaleUsers.php new file mode 100644 index 00000000..b1ef99d3 --- /dev/null +++ b/app/Console/Commands/DeleteStaleUsers.php @@ -0,0 +1,85 @@ +userService = $userService; + } + + public function handle(): int + { + $this->info('Finding stale users...'); + + $staleUsers = $this->userService->getStaleUsers(); + + if ($staleUsers->isEmpty()) { + $this->info('No stale users found.'); + return Command::SUCCESS; + } + $count = $staleUsers->count(); + $this->warn("Found {$count} stale user(s)."); + + $this->table( + ['ID', 'Username', 'Email', 'Last Updated'], + $staleUsers->map(function ($user) { + return [ + $user->id, + $user->username, + $user->email, + $user->updated_at->format('Y-m-d H:i:s'), + ]; + })->all() + ); + + if (!$this->option('force')) { + if (!$this->confirm("Are you sure you want to delete these {$count} user(s)? This action cannot be undone.")) { + $this->info('Operation cancelled by user.'); + return Command::SUCCESS; + } + } + + $this->info('Proceeding with deletion...'); + + $deletedCount = 0; + $errorCount = 0; + + foreach ($staleUsers as $user) { + try { + if ($user->forceDelete()) { + $this->info("User ID: {$user->id} ({$user->username}) deleted successfully."); + $deletedCount++; + } else { + $this->error("Failed to delete User ID: {$user->id} ({$user->username})."); + $errorCount++; + } + } catch (Throwable $e) { + $this->error("Error deleting User ID: {$user->id} ({$user->username}): " . $e->getMessage()); + $errorCount++; + } + + } + + $this->info("Deletion process completed. {$deletedCount} user(s) deleted."); + if ($errorCount > 0) { + $this->error("{$errorCount} user(s) could not be deleted. Check logs for details."); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +}