Skip to content

Commit 66530af

Browse files
authored
Merge pull request #14 from sourcetoad/fixes
Ensure we lock database searches to prevent dirty saves
2 parents 394dd5b + afc1697 commit 66530af

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/Models/AuditActivity.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public function getHumanVerbAttribute(): string
7676
return trans('logger::enums.verb_post');
7777

7878
case HttpVerb::PATCH:
79-
return trans('logger::enums.verb_patch');
80-
8179
case HttpVerb::PUT:
8280
return trans('logger::enums.verb_patch');
8381

@@ -142,4 +140,4 @@ public function entity()
142140
{
143141
return $this->morphTo();
144142
}
145-
}
143+
}

src/Models/AuditKey.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static function createOrFind(array $keys): AuditKey
5454

5555
/** @var AuditKey $key */
5656
$key = AuditKey::query()
57+
->lockForUpdate()
5758
->firstOrCreate([
5859
'hash' => $jsonHash
5960
], [
@@ -62,4 +63,4 @@ public static function createOrFind(array $keys): AuditKey
6263

6364
return $key;
6465
}
65-
}
66+
}

src/Models/AuditModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AuditModel extends BaseModel
4343
public static function createOrFind(AuditActivity $activity, int $modelType, int $modelId): AuditModel
4444
{
4545
/** @var AuditModel $model */
46-
$model = AuditModel::query()->create([
46+
$model = AuditModel::query()->lockForUpdate()->create([
4747
'activity_id' => $activity->id,
4848
'entity_type' => $modelType,
4949
'entity_id' => $modelId,
@@ -65,4 +65,4 @@ public function entity()
6565
{
6666
return $this->morphTo();
6767
}
68-
}
68+
}

src/Models/AuditRoute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static function createOrFind(string $route): AuditRoute
4242
$routeHash = md5(strtolower(trim($route)));
4343

4444
/** @var AuditRoute $route */
45-
$route = AuditRoute::query()->firstOrCreate([
45+
$route = AuditRoute::query()->lockForUpdate()->firstOrCreate([
4646
'route_hash' => $routeHash,
4747
], [
4848
'route' => $route,
4949
]);
5050

5151
return $route;
5252
}
53-
}
53+
}

0 commit comments

Comments
 (0)