Table locking for public_id integrity

This commit is contained in:
David Bomba 2016-02-10 11:26:21 +11:00
parent 04807bccc6
commit 67b74b2a34
2 changed files with 6 additions and 0 deletions

View File

@ -27,6 +27,7 @@ class EntityModel extends Eloquent
$lastEntity = $className::withTrashed()
->scope(false, $entity->account_id)
->orderBy('public_id', 'DESC')
->lockForUpdate()
->first();
if ($lastEntity) {

View File

@ -66,6 +66,8 @@ class ClientRepository extends BaseRepository
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
DB::beginTransaction();
if (!$publicId || $publicId == '-1') {
$client = Client::createNew();
} else {
@ -75,6 +77,9 @@ class ClientRepository extends BaseRepository
$client->fill($data);
$client->save();
DB::commit();
/*
if ( ! isset($data['contact']) && ! isset($data['contacts'])) {
return $client;