* Database health checks * Cache health checks * Storage write and disk-space checks * Failed queue job monitoring * Production environment diagnostics * Persisted health-check history * Queue retry controls * Scheduler execution controls * Cache and optimisation clearing * Backup creation and retention * Backup deletion * SQLite database backup support * Backup manifests and module metadata * Artisan health and backup commands * Administration navigation * Enterprise permissions * Module registration and tests
75 lines
2.6 KiB
PHP
75 lines
2.6 KiB
PHP
<?php
|
|
namespace Modules\Enterprise\Http\Controllers;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\View\View;
|
|
use Modules\Enterprise\Models\Backup;
|
|
use Modules\Enterprise\Models\HealthRun;
|
|
use Modules\Enterprise\Services\BackupService;
|
|
use Modules\Enterprise\Services\SystemHealthService;
|
|
use Throwable;
|
|
|
|
final class EnterpriseController
|
|
{
|
|
public function index(SystemHealthService $health): View
|
|
{
|
|
return view('enterprise::admin.index', [
|
|
'health' => $health->run(),
|
|
'latestRun' => HealthRun::latest('ran_at')->first(),
|
|
'backups' => Backup::latest()->limit(10)->get(),
|
|
'failedJobs' => DB::getSchemaBuilder()->hasTable('failed_jobs') ? DB::table('failed_jobs')->count() : 0,
|
|
'queueConnection' => config('queue.default'),
|
|
'cacheStore' => config('cache.default'),
|
|
'schedulerConfigured' => file_exists(base_path('routes/console.php')),
|
|
'phpVersion' => PHP_VERSION,
|
|
'laravelVersion' => app()->version(),
|
|
]);
|
|
}
|
|
|
|
public function runHealth(SystemHealthService $service): RedirectResponse
|
|
{
|
|
$result = $service->run();
|
|
HealthRun::create(['user_id' => auth()->id(), 'status' => $result['status'], 'results' => $result, 'ran_at' => now()]);
|
|
return back()->with('status', 'Health checks completed.');
|
|
}
|
|
|
|
public function clearCache(): RedirectResponse
|
|
{
|
|
Artisan::call('optimize:clear');
|
|
Cache::flush();
|
|
return back()->with('status', 'Application and cache stores cleared.');
|
|
}
|
|
|
|
public function runScheduler(): RedirectResponse
|
|
{
|
|
Artisan::call('schedule:run');
|
|
return back()->with('status', trim(Artisan::output()) ?: 'Scheduler executed.');
|
|
}
|
|
|
|
public function retryFailedJobs(): RedirectResponse
|
|
{
|
|
Artisan::call('queue:retry', ['id' => 'all']);
|
|
return back()->with('status', trim(Artisan::output()) ?: 'Failed jobs queued for retry.');
|
|
}
|
|
|
|
public function createBackup(BackupService $service): RedirectResponse
|
|
{
|
|
try {
|
|
$service->create(auth()->id());
|
|
return back()->with('status', 'Backup created.');
|
|
} catch (Throwable $e) {
|
|
report($e);
|
|
return back()->withErrors(['backup' => $e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function deleteBackup(Backup $backup, BackupService $service): RedirectResponse
|
|
{
|
|
$service->delete($backup);
|
|
return back()->with('status', 'Backup deleted.');
|
|
}
|
|
}
|