Skip to content

Commit e7f74fe

Browse files
committed
qc edits
1 parent 3850cf1 commit e7f74fe

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

app/Console/Commands/CertificateReassignUser.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ public function handle(): int
6363
])->toArray();
6464
$this->table(['id', 'edition', 'type', 'has PDF', 'sent'], $table);
6565

66+
// Check first: target must not already have an excellence for the same edition+type (unique constraint)
67+
$conflicts = [];
68+
foreach ($rows as $e) {
69+
$exists = Excellence::where('user_id', $toUser->id)
70+
->where('edition', $e->edition)
71+
->where('type', $e->type)
72+
->exists();
73+
if ($exists) {
74+
$conflicts[] = "edition {$e->edition}, type {$e->type}";
75+
}
76+
}
77+
if (count($conflicts) > 0) {
78+
$this->newLine();
79+
$this->error('Cannot reassign: target user already has certificate(s) for the same edition+type:');
80+
foreach ($conflicts as $c) {
81+
$this->line(' - ' . $c);
82+
}
83+
$this->line('Resolve duplicates (e.g. merge or delete one side) before reassigning.');
84+
return self::FAILURE;
85+
}
86+
6687
if ($dryRun) {
6788
$this->newLine();
6889
$this->warn('Dry run: no changes made. Run without --dry-run to reassign.');

0 commit comments

Comments
 (0)