]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegeneratePermissionsCommand.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Console / Commands / RegeneratePermissionsCommand.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use BookStack\Permissions\JointPermissionBuilder;
6 use Illuminate\Console\Command;
7 use Illuminate\Support\Facades\DB;
8
9 class RegeneratePermissionsCommand extends Command
10 {
11     /**
12      * The name and signature of the console command.
13      *
14      * @var string
15      */
16     protected $signature = 'bookstack:regenerate-permissions 
17                             {--database= : The database connection to use}';
18
19     /**
20      * The console command description.
21      *
22      * @var string
23      */
24     protected $description = 'Regenerate all system permissions';
25
26     /**
27      * Execute the console command.
28      */
29     public function handle(JointPermissionBuilder $permissionBuilder): int
30     {
31         $connection = DB::getDefaultConnection();
32
33         if ($this->option('database')) {
34             DB::setDefaultConnection($this->option('database'));
35         }
36
37         $permissionBuilder->rebuildForAll();
38
39         DB::setDefaultConnection($connection);
40         $this->comment('Permissions regenerated');
41
42         return 0;
43     }
44 }