]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegeneratePermissions.php
Allow book, shelf, settings & profile form input validation to skip image
[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      * @param \BookStack\Auth\\BookStack\Auth\Permissions\PermissionService $permissionService
35      */
36     public function __construct(PermissionService $permissionService)
37     {
38         $this->permissionService = $permissionService;
39         parent::__construct();
40     }
41
42     /**
43      * Execute the console command.
44      *
45      * @return mixed
46      */
47     public function handle()
48     {
49         $connection = \DB::getDefaultConnection();
50         if ($this->option('database') !== null) {
51             \DB::setDefaultConnection($this->option('database'));
52             $this->permissionService->setConnection(\DB::connection($this->option('database')));
53         }
54
55         $this->permissionService->buildJointPermissions();
56
57         \DB::setDefaultConnection($connection);
58         $this->comment('Permissions regenerated');
59     }
60 }