@@ -186,7 +186,7 @@ public function removePolicy(string $sec, string $ptype, array $rule): void
186
186
*/
187
187
public function removePolicies (string $ sec , string $ ptype , array $ rules ): void
188
188
{
189
- DB :: transaction (function () use ($ sec , $ rules , $ ptype ) {
189
+ $ this -> eloquent -> getConnection ()-> transaction (function () use ($ sec , $ rules , $ ptype ) {
190
190
foreach ($ rules as $ rule ) {
191
191
$ this ->removePolicy ($ sec , $ ptype , $ rule );
192
192
}
@@ -256,7 +256,11 @@ public function updatePolicy(string $sec, string $ptype, array $oldRule, array $
256
256
foreach ($ oldRule as $ k => $ v ) {
257
257
$ instance ->where ('v ' . $ k , $ v );
258
258
}
259
- $ instance ->first ();
259
+ $ instance = $ instance ->first ();
260
+ if (!$ instance ) {
261
+ return ;
262
+ }
263
+
260
264
$ update = [];
261
265
foreach ($ newPolicy as $ k => $ v ) {
262
266
$ update ['v ' . $ k ] = $ v ;
@@ -276,7 +280,7 @@ public function updatePolicy(string $sec, string $ptype, array $oldRule, array $
276
280
*/
277
281
public function updatePolicies (string $ sec , string $ ptype , array $ oldRules , array $ newRules ): void
278
282
{
279
- DB :: transaction (function () use ($ sec , $ ptype , $ oldRules , $ newRules ) {
283
+ $ this -> eloquent -> getConnection ()-> transaction (function () use ($ sec , $ ptype , $ oldRules , $ newRules ) {
280
284
foreach ($ oldRules as $ i => $ oldRule ) {
281
285
$ this ->updatePolicy ($ sec , $ ptype , $ oldRule , $ newRules [$ i ]);
282
286
}
@@ -296,7 +300,7 @@ public function updatePolicies(string $sec, string $ptype, array $oldRules, arra
296
300
public function updateFilteredPolicies (string $ sec , string $ ptype , array $ newPolicies , int $ fieldIndex , string ...$ fieldValues ): array
297
301
{
298
302
$ 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 ) {
300
304
$ oldRules = $ this ->_removeFilteredPolicy ($ sec , $ ptype , $ fieldIndex , ...$ fieldValues );
301
305
$ this ->addPolicies ($ sec , $ ptype , $ newPolicies );
302
306
});
0 commit comments