Files
Atomcms-edit/app/Http/Middleware/SystemCheck.php
T
2026-05-09 17:32:17 +02:00

55 lines
1.7 KiB
PHP
Executable File

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
class SystemCheck
{
public function handle(Request $request, Closure $next)
{
$checks = [];
// 1. Check .env exists
if (! file_exists(base_path('.env'))) {
if (file_exists(base_path('.env.example'))) {
copy(base_path('.env.example'), base_path('.env'));
Artisan::call('key:generate', ['--no-interaction' => true]);
$checks[] = 'Created .env from example';
}
}
// 2. Check APP_KEY
if (empty(Config::get('app.key'))) {
Artisan::call('key:generate', ['--no-interaction' => true]);
$checks[] = 'Generated APP_KEY';
}
// 3. Check storage symlink
if (! file_exists(public_path('storage'))) {
Artisan::call('storage:link');
$checks[] = 'Created storage symlink';
}
// 4. Check required PHP extensions
$required = ['pdo_mysql', 'curl', 'mbstring', 'openssl', 'tokenizer'];
$missing = array_filter($required, fn ($ext) => ! extension_loaded($ext));
if (! empty($missing)) {
return response()->json([
'error' => 'Missing PHP extensions: ' . implode(', ', $missing),
'solution' => 'Install: apt install php-' . implode(' php-', $missing),
], 500);
}
// 5. Log any auto-fixes
if (! empty($checks)) {
\Log::info('SystemCheck auto-fixed: ' . implode(', ', $checks));
}
return $next($request);
}
}