]> BookStack Code Mirror - bookstack/blobdiff - app/Console/Commands/RegeneratePermissions.php
Guest create page: name field autofocus
[bookstack] / app / Console / Commands / RegeneratePermissions.php
index bd221c1384816bbd8ffa46290ef856065fdcf852..efb3535d6484ba420fa41e34dc1cf6067f2fc6c5 100644 (file)
@@ -2,8 +2,9 @@
 
 namespace BookStack\Console\Commands;
 
-use BookStack\Services\RestrictionService;
+use BookStack\Auth\Permissions\JointPermissionBuilder;
 use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
 
 class RegeneratePermissions extends Command
 {
@@ -12,7 +13,7 @@ class RegeneratePermissions extends Command
      *
      * @var string
      */
-    protected $signature = 'permissions:regen';
+    protected $signature = 'bookstack:regenerate-permissions {--database= : The database connection to use.}';
 
     /**
      * The console command description.
@@ -21,21 +22,14 @@ class RegeneratePermissions extends Command
      */
     protected $description = 'Regenerate all system permissions';
 
-    /**
-     * The service to handle the permission system.
-     *
-     * @var RestrictionService
-     */
-    protected $restrictionService;
+    protected JointPermissionBuilder $permissionBuilder;
 
     /**
      * Create a new command instance.
-     *
-     * @param RestrictionService $restrictionService
      */
-    public function __construct(RestrictionService $restrictionService)
+    public function __construct(JointPermissionBuilder $permissionBuilder)
     {
-        $this->restrictionService = $restrictionService;
+        $this->permissionBuilder = $permissionBuilder;
         parent::__construct();
     }
 
@@ -46,6 +40,17 @@ class RegeneratePermissions extends Command
      */
     public function handle()
     {
-        $this->restrictionService->buildEntityPermissions();
+        $connection = DB::getDefaultConnection();
+
+        if ($this->option('database')) {
+            DB::setDefaultConnection($this->option('database'));
+        }
+
+        $this->permissionBuilder->rebuildForAll();
+
+        DB::setDefaultConnection($connection);
+        $this->comment('Permissions regenerated');
+
+        return 0;
     }
 }