mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for client number race conditions when importing stripe clients
This commit is contained in:
parent
aeda0af082
commit
44cd369256
@ -26,6 +26,7 @@ use App\PaymentDrivers\StripePaymentDriver;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Stripe\Customer;
|
||||
use Stripe\PaymentMethod;
|
||||
|
||||
@ -37,6 +38,8 @@ class ImportCustomers
|
||||
/** @var StripePaymentDriver */
|
||||
public $stripe;
|
||||
|
||||
private bool $completed = true;
|
||||
|
||||
public $update_payment_methods;
|
||||
|
||||
public function __construct(StripePaymentDriver $stripe)
|
||||
@ -132,10 +135,30 @@ class ImportCustomers
|
||||
$client->name = $customer->name ? $customer->name : $customer->email;
|
||||
|
||||
if (! isset($client->number) || empty($client->number)) {
|
||||
$client->number = $this->getNextClientNumber($client);
|
||||
}
|
||||
|
||||
$x = 1;
|
||||
|
||||
do {
|
||||
try {
|
||||
$client->number = $this->getNextClientNumber($client);
|
||||
$client->saveQuietly();
|
||||
|
||||
$this->completed = false;
|
||||
} catch (QueryException $e) {
|
||||
$x++;
|
||||
|
||||
if ($x > 10) {
|
||||
$this->completed = false;
|
||||
}
|
||||
}
|
||||
} while ($this->completed);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
$client->save();
|
||||
}
|
||||
|
||||
$contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||
$contact->client_id = $client->id;
|
||||
|
Loading…
Reference in New Issue
Block a user