From 6ddacbebc48a8a5405eb63f32ce7fd44a41e96f5 Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Fri, 10 Oct 2025 12:37:18 +1300 Subject: [PATCH] Adds wildcards --- .../Commands/RemoveAppInstancesByEmail.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/RemoveAppInstancesByEmail.php b/app/Console/Commands/RemoveAppInstancesByEmail.php index d9b6f5e..179f09a 100644 --- a/app/Console/Commands/RemoveAppInstancesByEmail.php +++ b/app/Console/Commands/RemoveAppInstancesByEmail.php @@ -15,7 +15,7 @@ class RemoveAppInstancesByEmail extends Command * @var string */ protected $signature = 'polydock:remove-instances-by-email - {email : The email address to search for} + {email : The email address or pattern to search for (supports % wildcards)} {--dry-run : Show what would be removed without actually doing it} {--force : Skip confirmation prompt}'; @@ -24,7 +24,7 @@ class RemoveAppInstancesByEmail extends Command * * @var string */ - protected $description = 'Find all app instances with the given email address and set them to pending removal'; + protected $description = 'Find all app instances with the given email address or pattern and set them to pending removal'; /** * Execute the console command. @@ -35,19 +35,28 @@ public function handle() $isDryRun = $this->option('dry-run'); $force = $this->option('force'); - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - $this->error('Invalid email address provided.'); + // Check if this is a pattern (contains %) or exact email + $isPattern = str_contains($email, '%'); + + if (!$isPattern && !filter_var($email, FILTER_VALIDATE_EMAIL)) { + $this->error('Invalid email address provided. Use % for wildcard patterns (e.g., %@example.com).'); return 1; } - $this->info("Searching for app instances with email: {$email}"); + $searchType = $isPattern ? 'pattern' : 'email'; + $this->info("Searching for app instances with {$searchType}: {$email}"); - // Find all app instances with the given email in their data - $instances = PolydockAppInstance::whereJsonContains('data->user-email', $email)->get(); + // Find all app instances with the given email or pattern in their data + if ($isPattern) { + // Use raw SQL for pattern matching (compatible with MariaDB/MySQL) + $instances = PolydockAppInstance::whereRaw("JSON_UNQUOTE(JSON_EXTRACT(data, '$.\"user-email\"')) LIKE ?", [$email])->get(); + } else { + $instances = PolydockAppInstance::whereJsonContains('data->user-email', $email)->get(); + } if ($instances->isEmpty()) { - $this->info('No app instances found with the email address: ' . $email); + $this->info("No app instances found matching {$searchType}: {$email}"); return 0; } @@ -67,18 +76,19 @@ public function handle() return 0; } - $this->info("Found {$instances->count()} app instance(s) with email: {$email}"); + $this->info("Found {$instances->count()} app instance(s) matching {$searchType}: {$email}"); $this->info("Removable instances: {$removableInstances->count()}"); $this->newLine(); // Display the removable instances - $headers = ['ID', 'Name', 'Status', 'Store App', 'Created At']; + $headers = ['ID', 'Name', 'Email', 'Status', 'Store App', 'Created At']; $rows = []; foreach ($removableInstances as $instance) { $rows[] = [ $instance->id, $instance->name ?: 'N/A', + $instance->getUserEmail() ?: 'N/A', $instance->status->getLabel(), $instance->storeApp->name ?? 'N/A', $instance->created_at->format('Y-m-d H:i:s') @@ -116,7 +126,7 @@ public function handle() $instance->setStatus( PolydockAppInstanceStatus::PENDING_PRE_REMOVE, - "Marked for removal by email: {$email}" + "Marked for removal by {$searchType}: {$email}" ); $instance->save();