3 namespace BookStack\Console\Commands;
5 use BookStack\Auth\Permissions\JointPermissionBuilder;
6 use Illuminate\Console\Command;
7 use Illuminate\Support\Facades\DB;
9 class RegeneratePermissions extends Command
12 * The name and signature of the console command.
16 protected $signature = 'bookstack:regenerate-permissions {--database= : The database connection to use.}';
19 * The console command description.
23 protected $description = 'Regenerate all system permissions';
25 protected JointPermissionBuilder $permissionBuilder;
28 * Create a new command instance.
30 public function __construct(JointPermissionBuilder $permissionBuilder)
32 $this->permissionBuilder = $permissionBuilder;
33 parent::__construct();
37 * Execute the console command.
41 public function handle()
43 $connection = DB::getDefaultConnection();
45 if ($this->option('database')) {
46 DB::setDefaultConnection($this->option('database'));
49 $this->permissionBuilder->rebuildForAll();
51 DB::setDefaultConnection($connection);
52 $this->comment('Permissions regenerated');