2016-04-23 13:14:26 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2023-05-17 12:56:55 -04:00
|
|
|
use BookStack\Permissions\JointPermissionBuilder;
|
2016-04-23 13:14:26 -04:00
|
|
|
use Illuminate\Console\Command;
|
2022-07-12 14:38:11 -04:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-04-23 13:14:26 -04:00
|
|
|
|
|
|
|
class RegeneratePermissions extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-03-26 14:24:57 -04:00
|
|
|
protected $signature = 'bookstack:regenerate-permissions {--database= : The database connection to use.}';
|
2016-04-23 13:14:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Regenerate all system permissions';
|
|
|
|
|
2022-07-12 14:38:11 -04:00
|
|
|
protected JointPermissionBuilder $permissionBuilder;
|
2016-04-23 13:14:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*/
|
2022-07-12 14:38:11 -04:00
|
|
|
public function __construct(JointPermissionBuilder $permissionBuilder)
|
2016-04-23 13:14:26 -04:00
|
|
|
{
|
2022-07-12 14:38:11 -04:00
|
|
|
$this->permissionBuilder = $permissionBuilder;
|
2016-04-23 13:14:26 -04:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-07-12 14:38:11 -04:00
|
|
|
$connection = DB::getDefaultConnection();
|
|
|
|
|
2022-07-12 15:15:41 -04:00
|
|
|
if ($this->option('database')) {
|
2022-07-12 14:38:11 -04:00
|
|
|
DB::setDefaultConnection($this->option('database'));
|
2017-03-26 14:24:57 -04:00
|
|
|
}
|
|
|
|
|
2022-07-12 15:15:41 -04:00
|
|
|
$this->permissionBuilder->rebuildForAll();
|
2017-03-26 14:24:57 -04:00
|
|
|
|
2022-07-12 14:38:11 -04:00
|
|
|
DB::setDefaultConnection($connection);
|
2017-02-26 04:14:18 -05:00
|
|
|
$this->comment('Permissions regenerated');
|
2022-08-29 12:46:41 -04:00
|
|
|
|
2022-08-17 09:39:53 -04:00
|
|
|
return 0;
|
2016-04-23 13:14:26 -04:00
|
|
|
}
|
|
|
|
}
|