57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Maintenance\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\Maintenance\Http\Controllers\Concerns\AuthorizesMaintenance;
|
|
use Modules\Maintenance\Services\MaintenanceHealthService;
|
|
use Modules\Maintenance\Utils\MaintenanceUtil;
|
|
|
|
class HealthController extends Controller
|
|
{
|
|
use AuthorizesMaintenance;
|
|
|
|
public function __construct(
|
|
protected MaintenanceHealthService $healthService,
|
|
protected MaintenanceUtil $maintenanceUtil
|
|
) {
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->authorizeMaintenanceAccess('maintenance.view');
|
|
|
|
$health = $this->healthService->assess();
|
|
|
|
return view('maintenance::health.index', compact('health'));
|
|
}
|
|
|
|
public function repair(Request $request)
|
|
{
|
|
$this->authorizeMaintenanceAccess('maintenance.access');
|
|
|
|
$result = $this->healthService->repair();
|
|
|
|
if ($request->wantsJson() || $request->ajax()) {
|
|
return response()->json([
|
|
'success' => $result['repaired'],
|
|
'result' => $result,
|
|
'msg' => $result['repaired']
|
|
? __('maintenance::lang.health_repair_success', ['score' => $result['after']['score']])
|
|
: __('maintenance::lang.health_repair_partial'),
|
|
]);
|
|
}
|
|
|
|
return redirect()
|
|
->action([self::class, 'index'])
|
|
->with('status', [
|
|
'success' => $result['repaired'],
|
|
'msg' => $result['repaired']
|
|
? __('maintenance::lang.health_repair_success', ['score' => $result['after']['score']])
|
|
: __('maintenance::lang.health_repair_partial'),
|
|
])
|
|
->with('health_result', $result);
|
|
}
|
|
}
|