2016-04-23 19:14:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2018-09-25 13:30:50 +02:00
|
|
|
use BookStack\Auth\Permissions\PermissionService;
|
2016-04-23 19:14:26 +02:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class RegeneratePermissions extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-03-26 20:24:57 +02:00
|
|
|
protected $signature = 'bookstack:regenerate-permissions {--database= : The database connection to use.}';
|
2016-04-23 19:14:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Regenerate all system permissions';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The service to handle the permission system.
|
|
|
|
*
|
2016-05-01 22:20:50 +02:00
|
|
|
* @var PermissionService
|
2016-04-23 19:14:26 +02:00
|
|
|
*/
|
2016-05-01 22:20:50 +02:00
|
|
|
protected $permissionService;
|
2016-04-23 19:14:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*/
|
2016-05-01 22:20:50 +02:00
|
|
|
public function __construct(PermissionService $permissionService)
|
2016-04-23 19:14:26 +02:00
|
|
|
{
|
2016-05-01 22:20:50 +02:00
|
|
|
$this->permissionService = $permissionService;
|
2016-04-23 19:14:26 +02:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2017-03-26 20:24:57 +02:00
|
|
|
$connection = \DB::getDefaultConnection();
|
|
|
|
if ($this->option('database') !== null) {
|
|
|
|
\DB::setDefaultConnection($this->option('database'));
|
2017-04-30 12:38:58 +02:00
|
|
|
$this->permissionService->setConnection(\DB::connection($this->option('database')));
|
2017-03-26 20:24:57 +02:00
|
|
|
}
|
|
|
|
|
2016-05-01 22:20:50 +02:00
|
|
|
$this->permissionService->buildJointPermissions();
|
2017-03-26 20:24:57 +02:00
|
|
|
|
|
|
|
\DB::setDefaultConnection($connection);
|
2017-02-26 10:14:18 +01:00
|
|
|
$this->comment('Permissions regenerated');
|
2016-04-23 19:14:26 +02:00
|
|
|
}
|
|
|
|
}
|