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