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
|
|
|
|
2023-05-24 08:21:46 -04:00
|
|
|
class RegeneratePermissionsCommand extends Command
|
2016-04-23 13:14:26 -04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-05-24 07:59:50 -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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2023-05-24 07:59:50 -04:00
|
|
|
public function handle(JointPermissionBuilder $permissionBuilder): int
|
2016-04-23 13:14:26 -04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2023-05-24 07:59:50 -04:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|