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