]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegeneratePermissions.php
efb3535d6484ba420fa41e34dc1cf6067f2fc6c5
[bookstack] / app / Console / Commands / RegeneratePermissions.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use BookStack\Auth\Permissions\JointPermissionBuilder;
6 use Illuminate\Console\Command;
7 use Illuminate\Support\Facades\DB;
8
9 class RegeneratePermissions extends Command
10 {
11     /**
12      * The name and signature of the console command.
13      *
14      * @var string
15      */
16     protected $signature = 'bookstack:regenerate-permissions {--database= : The database connection to use.}';
17
18     /**
19      * The console command description.
20      *
21      * @var string
22      */
23     protected $description = 'Regenerate all system permissions';
24
25     protected JointPermissionBuilder $permissionBuilder;
26
27     /**
28      * Create a new command instance.
29      */
30     public function __construct(JointPermissionBuilder $permissionBuilder)
31     {
32         $this->permissionBuilder = $permissionBuilder;
33         parent::__construct();
34     }
35
36     /**
37      * Execute the console command.
38      *
39      * @return mixed
40      */
41     public function handle()
42     {
43         $connection = DB::getDefaultConnection();
44
45         if ($this->option('database')) {
46             DB::setDefaultConnection($this->option('database'));
47         }
48
49         $this->permissionBuilder->rebuildForAll();
50
51         DB::setDefaultConnection($connection);
52         $this->comment('Permissions regenerated');
53
54         return 0;
55     }
56 }