Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 28 |
ListRoutesName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 28 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
handle | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 24 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiGateway\Console\Commands; |
4 | |
5 | use Illuminate\Support\Str; |
6 | use Qmp\Laravel\Acls\Models\Permission; |
7 | use Qmp\Laravel\Acls\Models\Role; |
8 | use Qmp\Laravel\CommandsLaravel\Middleware\Library\Monitoring\CreateParentProcess; |
9 | use Qmp\Laravel\CommandsLaravel\Middleware\Library\Monitoring\UpdateParentProcess; |
10 | use Qmp\Laravel\ToolsLaravel\Traits\Timer; |
11 | |
12 | class ListRoutesName extends \Commando |
13 | { |
14 | use Timer; |
15 | /** |
16 | * The name and signature of the console command. |
17 | * |
18 | * @var string |
19 | */ |
20 | protected $signature = 'gateway:generate-routes-permissions'; |
21 | |
22 | /** |
23 | * The console command description. |
24 | * |
25 | * @var string |
26 | */ |
27 | protected $description = 'List all routes names'; |
28 | |
29 | /** |
30 | * Create a new command instance. |
31 | * |
32 | * @return void |
33 | */ |
34 | public function __construct() |
35 | { |
36 | parent::__construct(); |
37 | $this->middleware([ |
38 | CreateParentProcess::class, |
39 | UpdateParentProcess::class |
40 | ]); |
41 | } |
42 | |
43 | /** |
44 | * Execute the console command. |
45 | * |
46 | * @return mixed |
47 | */ |
48 | public function handle() |
49 | { |
50 | $nothing = true; |
51 | |
52 | $this->startTimer('total'); |
53 | |
54 | $data = $this->middlewareData(UpdateParentProcess::class) |
55 | ->transfert(CreateParentProcess::class, ['id']); |
56 | |
57 | $data->log['synced'] = 0; |
58 | |
59 | collect(app()->routes->getRoutes())->map(function ($route) { |
60 | return $route->getName(); |
61 | })->filter(function ($name) { |
62 | return Str::startsWith($name, 'latest'); |
63 | })->each(function ($name) use (&$nothing, &$data) { |
64 | |
65 | $permission = Permission::firstOrNew(['name' => str_replace('latest.', '', $name)]); |
66 | |
67 | if ($permission->id === null) { |
68 | $nothing = false; |
69 | $this->info('Add ' . str_replace('latest.', '', $name)); |
70 | $data->log['synced']++; |
71 | $permission->save(); |
72 | } |
73 | }); |
74 | |
75 | if ($nothing) { |
76 | $this->info('No new permissions to add !'); |
77 | |
78 | } else { |
79 | $this->info('Syncing super admin permissions ...'); |
80 | $su = Role::where('name', 'super_admin')->first(); |
81 | $su->permissions()->sync(Permission::all()); |
82 | } |
83 | |
84 | $data->log['duration'] = $this->getTimer('total'); |
85 | } |
86 | } |