Skip to content

Commit 9fc9c75

Browse files
committed
edits
1 parent b4aa6ea commit 9fc9c75

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

app/Console/Commands/CertificatePreflight.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class CertificatePreflight extends Command
1414
{--limit=0 : Max records to test (0 = all)}
1515
{--batch-size=500 : Process in batches; 0 = single run}
1616
{--only-pending : Test only rows without certificate_url}
17+
{--emails= : Comma-separated emails to test only}
18+
{--emails-file= : Path to file with one email per line (to test only those)}
1719
{--export= : Optional CSV path for failures (only failures written)}';
1820

1921
protected $description = 'Dry-run compile certificates (no S3 upload, no DB updates) and report failures';
@@ -25,6 +27,8 @@ public function handle(): int
2527
$limit = max(0, (int) $this->option('limit'));
2628
$batchSize = max(0, (int) $this->option('batch-size'));
2729
$onlyPending = (bool) $this->option('only-pending');
30+
$emailsOption = trim((string) $this->option('emails'));
31+
$emailsFilePath = trim((string) $this->option('emails-file'));
2832
$exportPath = trim((string) $this->option('export'));
2933

3034
$types = $this->resolveTypes($typeOption);
@@ -33,23 +37,36 @@ public function handle(): int
3337
return self::FAILURE;
3438
}
3539

40+
$emailList = $this->resolveEmailList($emailsOption, $emailsFilePath);
41+
if ($emailList === null) {
42+
return self::FAILURE;
43+
}
44+
3645
$baseQuery = Excellence::query()
3746
->where('edition', $edition)
3847
->whereIn('type', $types)
3948
->with('user')
4049
->orderBy('type')
4150
->orderBy('id');
4251

52+
if (! empty($emailList)) {
53+
$baseQuery->whereHas('user', fn ($q) => $q->whereIn('email', $emailList));
54+
}
55+
4356
if ($onlyPending) {
4457
$baseQuery->whereNull('certificate_url');
4558
}
4659

4760
$totalToTest = (clone $baseQuery)->count();
4861
if ($totalToTest === 0) {
49-
$this->info('No recipients found for the selected filters.');
62+
$this->info(empty($emailList) ? 'No recipients found for the selected filters.' : 'No Excellence rows found for the given email list (edition/type may not match).');
5063
return self::SUCCESS;
5164
}
5265

66+
if (! empty($emailList)) {
67+
$this->info('Restricted to '.count($emailList).' email(s) from list; '.$totalToTest.' Excellence row(s) match.');
68+
}
69+
5370
if ($limit > 0) {
5471
$totalToTest = min($totalToTest, $limit);
5572
}
@@ -178,6 +195,36 @@ public function handle(): int
178195
return self::SUCCESS;
179196
}
180197

198+
/**
199+
* @return array<string>|null Returns list of emails, or null on error (e.g. file not found).
200+
*/
201+
private function resolveEmailList(string $emailsOption, string $emailsFilePath): ?array
202+
{
203+
$list = [];
204+
if ($emailsOption !== '') {
205+
foreach (array_map('trim', explode(',', $emailsOption)) as $e) {
206+
if ($e !== '') {
207+
$list[] = $e;
208+
}
209+
}
210+
}
211+
if ($emailsFilePath !== '') {
212+
$path = str_starts_with($emailsFilePath, '/') ? $emailsFilePath : base_path($emailsFilePath);
213+
if (! is_file($path) || ! is_readable($path)) {
214+
$this->error("Emails file not found or not readable: {$path}");
215+
return null;
216+
}
217+
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
218+
foreach ($lines as $line) {
219+
$e = trim($line);
220+
if ($e !== '') {
221+
$list[] = $e;
222+
}
223+
}
224+
}
225+
return array_values(array_unique($list));
226+
}
227+
181228
private function resolveTypes(string $typeOption): ?array
182229
{
183230
return match ($typeOption) {

0 commit comments

Comments
 (0)