fix(ledger): PayPal import survives a concurrent run of itself
A manual import overlapping the scheduled one could insert the same PayPal transaction twice and fail on the unique key. The loser now updates the row the other run created. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
644c84def3
commit
e2ea2ff9ab
|
|
@ -172,7 +172,19 @@ class PaypalLedgerService
|
||||||
return 'updated';
|
return 'updated';
|
||||||
}
|
}
|
||||||
|
|
||||||
$model::query()->create($row);
|
try {
|
||||||
|
$model::query()->create($row);
|
||||||
|
} catch (\Illuminate\Database\QueryException $e) {
|
||||||
|
// A concurrent import (manual run during the scheduled one) inserted
|
||||||
|
// the same transaction first: update that row instead.
|
||||||
|
$existing = $model::query()->where('stripe_id', $row['stripe_id'])->first();
|
||||||
|
if (! $existing) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
$existing->fill($row)->save();
|
||||||
|
|
||||||
|
return 'updated';
|
||||||
|
}
|
||||||
|
|
||||||
return 'created';
|
return 'created';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue