Skip to content

Commit

Permalink
fix: Amend part logic of removePolicies (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
basakest committed Jul 11, 2021
1 parent cc73dea commit f81f206
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/Adapters/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Casbin\Persist\AdapterHelper;
use DateTime;
use Casbin\Exceptions\InvalidFilterTypeException;
use Illuminate\Support\Facades\DB;
/**
* DatabaseAdapter.
*
Expand Down Expand Up @@ -167,20 +168,11 @@ public function removePolicy(string $sec, string $ptype, array $rule): void
*/
public function removePolicies(string $sec, string $ptype, array $rules): void
{
$instance = $this->eloquent->where('p_type', $ptype);
foreach($rules as $rule)
{
foreach ($rule as $key => $value) {
$keys[] = 'v'.strval($key);
$con['v'.strval($key)][] = $value;
DB::transaction(function () use ($sec, $rules, $ptype) {
foreach ($rules as $rule) {
$this->removePolicy($sec, $ptype, $rule);
}
}
$keys = array_unique($keys);
foreach($keys as $key){
$instance->whereIn($key, $con[$key]);
}
$instance->delete();
Rule::fireModelEvent('deleted');
});
}

/**
Expand Down

0 comments on commit f81f206

Please sign in to comment.