|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Actions\Admin\Settings; |
| 4 | + |
| 5 | +use App\Repositories\SystemInfoRepository; |
| 6 | +use App\Traits\CustomControllerResponsesTrait; |
| 7 | +use App\Traits\ThemesTrait; |
| 8 | +use Illuminate\Http\Request; |
| 9 | +use Illuminate\Validation\Rule; |
| 10 | +use Lorisleiva\Actions\Concerns\AsAction; |
| 11 | + |
| 12 | +class ResetSystem |
| 13 | +{ |
| 14 | + use AsAction; |
| 15 | + use ThemesTrait; |
| 16 | + use CustomControllerResponsesTrait; |
| 17 | + |
| 18 | + public function asController(Request $request) |
| 19 | + { |
| 20 | + $actions = [ |
| 21 | + [ |
| 22 | + 'text' => 'Clear Redis', |
| 23 | + 'action' => 'redis', |
| 24 | + ], |
| 25 | + [ |
| 26 | + 'text' => 'Clear Cached Views', |
| 27 | + 'action' => 'views', |
| 28 | + ], |
| 29 | + [ |
| 30 | + 'text' => 'Refresh Configurations (Settings)', |
| 31 | + 'action' => 'configurations', |
| 32 | + ], |
| 33 | + [ |
| 34 | + 'text' => 'Update Configurations (Settings)', |
| 35 | + 'action' => 'update-configurations', |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'text' => 'Truncate & Reset Configurations (Settings)', |
| 39 | + 'action' => 'reset-configurations', |
| 40 | + ], |
| 41 | + [ |
| 42 | + 'text' => 'Run Seeder', |
| 43 | + 'action' => 'run-seeder', |
| 44 | + ], |
| 45 | + [ |
| 46 | + 'text' => 'Seed Demo Data', |
| 47 | + 'action' => 'seed-demo-data', |
| 48 | + ], |
| 49 | + ]; |
| 50 | + |
| 51 | + if($request->isMethod('get')) { |
| 52 | + |
| 53 | + return $this->generateBackendPage('Admin/Settings/ResetSystem', [ |
| 54 | + 'actions' => $actions, |
| 55 | + ]); |
| 56 | + } |
| 57 | + |
| 58 | + $request->validate([ |
| 59 | + 'action' => [ |
| 60 | + 'required', |
| 61 | + 'string', |
| 62 | + Rule::in(collect($actions)->pluck('action')->toArray()), |
| 63 | + ] |
| 64 | + ]); |
| 65 | + |
| 66 | + $repo = resolve(SystemInfoRepository::class); |
| 67 | + $status = $repo->reset($request->action); |
| 68 | + |
| 69 | + if($status) { |
| 70 | + // TODO: event |
| 71 | + return $this->respSuccess(); |
| 72 | + } |
| 73 | + |
| 74 | + return $this->respError(); |
| 75 | + } |
| 76 | +} |
0 commit comments