Skip to content

Commit f81f206

Browse files
authored
fix: Amend part logic of removePolicies (#24)
1 parent cc73dea commit f81f206

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/Adapters/DatabaseAdapter.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Casbin\Persist\AdapterHelper;
1515
use DateTime;
1616
use Casbin\Exceptions\InvalidFilterTypeException;
17+
use Illuminate\Support\Facades\DB;
1718
/**
1819
* DatabaseAdapter.
1920
*
@@ -167,20 +168,11 @@ public function removePolicy(string $sec, string $ptype, array $rule): void
167168
*/
168169
public function removePolicies(string $sec, string $ptype, array $rules): void
169170
{
170-
$instance = $this->eloquent->where('p_type', $ptype);
171-
foreach($rules as $rule)
172-
{
173-
foreach ($rule as $key => $value) {
174-
$keys[] = 'v'.strval($key);
175-
$con['v'.strval($key)][] = $value;
171+
DB::transaction(function () use ($sec, $rules, $ptype) {
172+
foreach ($rules as $rule) {
173+
$this->removePolicy($sec, $ptype, $rule);
176174
}
177-
}
178-
$keys = array_unique($keys);
179-
foreach($keys as $key){
180-
$instance->whereIn($key, $con[$key]);
181-
}
182-
$instance->delete();
183-
Rule::fireModelEvent('deleted');
175+
});
184176
}
185177

186178
/**

0 commit comments

Comments
 (0)