mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-21 00:41:34 +02: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\Ninja;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Stripe\Customer;
|
use Stripe\Customer;
|
||||||
use Stripe\PaymentMethod;
|
use Stripe\PaymentMethod;
|
||||||
|
|
||||||
@ -37,6 +38,8 @@ class ImportCustomers
|
|||||||
/** @var StripePaymentDriver */
|
/** @var StripePaymentDriver */
|
||||||
public $stripe;
|
public $stripe;
|
||||||
|
|
||||||
|
private bool $completed = true;
|
||||||
|
|
||||||
public $update_payment_methods;
|
public $update_payment_methods;
|
||||||
|
|
||||||
public function __construct(StripePaymentDriver $stripe)
|
public function __construct(StripePaymentDriver $stripe)
|
||||||
@ -132,10 +135,30 @@ class ImportCustomers
|
|||||||
$client->name = $customer->name ? $customer->name : $customer->email;
|
$client->name = $customer->name ? $customer->name : $customer->email;
|
||||||
|
|
||||||
if (! isset($client->number) || empty($client->number)) {
|
if (! isset($client->number) || empty($client->number)) {
|
||||||
$client->number = $this->getNextClientNumber($client);
|
|
||||||
}
|
|
||||||
|
|
||||||
$client->save();
|
$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 = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||||
$contact->client_id = $client->id;
|
$contact->client_id = $client->id;
|
||||||
|
Loading…
Reference in New Issue
Block a user