Skip to content

Commit 774857a

Browse files
authored
Merge pull request #53 from cidosx/master
Improve DatabaseAdapter
2 parents 5de36c5 + 7e21d0c commit 774857a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Adapters/DatabaseAdapter.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function removePolicy(string $sec, string $ptype, array $rule): void
186186
*/
187187
public function removePolicies(string $sec, string $ptype, array $rules): void
188188
{
189-
DB::transaction(function () use ($sec, $rules, $ptype) {
189+
$this->eloquent->getConnection()->transaction(function () use ($sec, $rules, $ptype) {
190190
foreach ($rules as $rule) {
191191
$this->removePolicy($sec, $ptype, $rule);
192192
}
@@ -256,7 +256,11 @@ public function updatePolicy(string $sec, string $ptype, array $oldRule, array $
256256
foreach($oldRule as $k => $v) {
257257
$instance->where('v' . $k, $v);
258258
}
259-
$instance->first();
259+
$instance = $instance->first();
260+
if (!$instance) {
261+
return;
262+
}
263+
260264
$update = [];
261265
foreach($newPolicy as $k => $v) {
262266
$update['v' . $k] = $v;
@@ -276,7 +280,7 @@ public function updatePolicy(string $sec, string $ptype, array $oldRule, array $
276280
*/
277281
public function updatePolicies(string $sec, string $ptype, array $oldRules, array $newRules): void
278282
{
279-
DB::transaction(function () use ($sec, $ptype, $oldRules, $newRules) {
283+
$this->eloquent->getConnection()->transaction(function () use ($sec, $ptype, $oldRules, $newRules) {
280284
foreach ($oldRules as $i => $oldRule) {
281285
$this->updatePolicy($sec, $ptype, $oldRule, $newRules[$i]);
282286
}
@@ -296,7 +300,7 @@ public function updatePolicies(string $sec, string $ptype, array $oldRules, arra
296300
public function updateFilteredPolicies(string $sec, string $ptype, array $newPolicies, int $fieldIndex, string ...$fieldValues): array
297301
{
298302
$oldRules = [];
299-
DB::transaction(function () use ($sec, $ptype, $fieldIndex, $fieldValues, $newPolicies, &$oldRules) {
303+
$this->eloquent->getConnection()->transaction(function () use ($sec, $ptype, $fieldIndex, $fieldValues, $newPolicies, &$oldRules) {
300304
$oldRules = $this->_removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues);
301305
$this->addPolicies($sec, $ptype, $newPolicies);
302306
});

0 commit comments

Comments
 (0)