1111use craft \web \Session ;
1212use craft \web \View ;
1313use CraftCms \Cms \Support \Json ;
14+ use Illuminate \Support \Facades \Cache ;
1415use yii \base \Behavior ;
1516use yii \base \Exception ;
1617use yii \web \AssetBundle ;
@@ -266,19 +267,14 @@ public function broadcastToJs(string|array $message): void
266267 */
267268 public function authorize (string $ action ): void
268269 {
269- $ mutex = Craft::$ app ->getMutex ();
270- $ locked = $ mutex ->acquire (self ::AUTH_LOCK_NAME , 5 );
271-
272- $ access = $ this ->owner ->get ($ this ->authAccessParam , []);
273-
274- if (!in_array ($ action , $ access , true )) {
275- $ access [] = $ action ;
276- $ this ->owner ->set ($ this ->authAccessParam , $ access );
277- }
278-
279- if ($ locked ) {
280- $ mutex ->release (self ::AUTH_LOCK_NAME );
281- }
270+ Cache::lock (self ::AUTH_LOCK_NAME )->block (5 , function () use ($ action ) {
271+ $ access = $ this ->owner ->get ($ this ->authAccessParam , []);
272+
273+ if (!in_array ($ action , $ access , true )) {
274+ $ access [] = $ action ;
275+ $ this ->owner ->set ($ this ->authAccessParam , $ access );
276+ }
277+ });
282278 }
283279
284280 /**
@@ -288,20 +284,15 @@ public function authorize(string $action): void
288284 */
289285 public function deauthorize (string $ action ): void
290286 {
291- $ mutex = Craft::$ app ->getMutex ();
292- $ locked = $ mutex ->acquire (self ::AUTH_LOCK_NAME , 5 );
293-
294- $ access = $ this ->owner ->get ($ this ->authAccessParam , []);
295- $ index = array_search ($ action , $ access , true );
296-
297- if ($ index !== false ) {
298- array_splice ($ access , $ index , 1 );
299- $ this ->owner ->set ($ this ->authAccessParam , $ access );
300- }
301-
302- if ($ locked ) {
303- $ mutex ->release (self ::AUTH_LOCK_NAME );
304- }
287+ Cache::lock (self ::AUTH_LOCK_NAME )->block (5 , function () use ($ action ) {
288+ $ access = $ this ->owner ->get ($ this ->authAccessParam , []);
289+ $ index = array_search ($ action , $ access , true );
290+
291+ if ($ index !== false ) {
292+ array_splice ($ access , $ index , 1 );
293+ $ this ->owner ->set ($ this ->authAccessParam , $ access );
294+ }
295+ });
305296 }
306297
307298 /**
0 commit comments