getExtension() === 'php' && strpos($file->getFilename(), '.blade.') !== false) { $files[] = $file->getPathname(); } } return $files; } /** * Effettua il backup del file */ function backupFile($filePath, $backupPath, $basePath) { $relativePath = str_replace($basePath . '/', '', $filePath); $backupFilePath = $backupPath . '/' . $relativePath; // Crea le directory necessarie $backupDir = dirname($backupFilePath); if (!is_dir($backupDir)) { mkdir($backupDir, 0755, true); } return copy($filePath, $backupFilePath); } /** * Applica le correzioni a un file */ function fixFile($filePath) { $content = file_get_contents($filePath); $originalContent = $content; $changes = []; // 1. Fix β†’ @extends('admin.layouts.app') if (preg_match('/]*>/', $content)) { $content = preg_replace('/]*>/', '', $content); $content = preg_replace('/<\/x-app-layout>/', '', $content); // Aggiungi @extends all'inizio if (!preg_match('/@extends\(/', $content)) { $content = "@extends('admin.layouts.app')\n\n@section('title', 'Pagina Admin')\n\n@section('content')\n" . $content . "\n@endsection"; $changes[] = 'Sostituito con @extends'; } } // 2. Fix β†’ sezioni Blade if (preg_match('/]*>(.*?)<\/x-slot>/s', $content, $matches)) { $headerContent = trim($matches[1]); $content = preg_replace('/]*>.*?<\/x-slot>/s', '', $content); // Estrai il titolo se presente if (preg_match('/]*>(.*?)<\/h2>/s', $headerContent, $titleMatch)) { $title = strip_tags($titleMatch[1]); $content = preg_replace('/@section\([\'"]title[\'"],\s*[\'"][^\'"]*[\'"]/', "@section('title', '" . addslashes($title) . "'", $content); } $changes[] = 'Convertito header'; } // 3. Aggiungi @section('title') se mancante if (preg_match('/@extends\(/', $content) && !preg_match('/@section\([\'"]title[\'"]/', $content)) { $content = preg_replace('/(@extends\([^\)]+\))/', "$1\n\n@section('title', 'Pagina Admin')", $content); $changes[] = 'Aggiunto @section(\'title\')'; } // 4. Fix classi Tailwind comuni β†’ Bootstrap $tailwindToBootstrap = [ // Layout 'py-12' => 'py-5', 'px-4' => 'px-3', 'px-6' => 'px-4', 'py-4' => 'py-3', 'py-6' => 'py-4', 'max-w-7xl' => 'container-fluid', 'mx-auto' => 'mx-auto', // Colori di sfondo 'bg-white' => 'bg-white', 'bg-gray-800' => 'bg-dark', 'bg-gray-50' => 'bg-light', 'bg-blue-500' => 'bg-primary', 'bg-green-500' => 'bg-success', 'bg-red-500' => 'bg-danger', 'bg-yellow-500' => 'bg-warning', // Colori del testo 'text-gray-800' => 'text-dark', 'text-gray-600' => 'text-muted', 'text-gray-500' => 'text-muted', 'text-white' => 'text-white', 'text-blue-600' => 'text-primary', 'text-green-600' => 'text-success', 'text-red-600' => 'text-danger', // Flex 'flex' => 'd-flex', 'items-center' => 'align-items-center', 'justify-between' => 'justify-content-between', 'justify-center' => 'justify-content-center', // Grid 'grid-cols-1' => 'row', 'grid-cols-2' => 'row', 'grid-cols-3' => 'row', 'col-span-1' => 'col-md-12', // Spacing 'space-x-2' => 'gap-2', 'space-x-3' => 'gap-3', 'space-y-4' => 'gap-4', // Buttons 'font-bold' => 'fw-bold', 'py-2' => 'py-2', 'px-4' => 'px-3', 'rounded' => 'rounded', 'hover:bg-blue-700' => '', // Tables 'min-w-full' => 'table', 'divide-y' => 'table-bordered', 'divide-gray-200' => '', 'whitespace-nowrap' => 'text-nowrap', // Forms 'border-gray-300' => 'form-control', 'rounded-md' => 'rounded', 'shadow-sm' => '', // Utilities 'overflow-hidden' => 'overflow-hidden', 'shadow-sm' => 'shadow-sm', 'sm:rounded-lg' => 'rounded', 'dark:bg-gray-800' => '', 'dark:text-gray-200' => '', 'dark:border-gray-700' => '', ]; foreach ($tailwindToBootstrap as $tailwind => $bootstrap) { if (strpos($content, $tailwind) !== false) { $content = str_replace($tailwind, $bootstrap, $content); $changes[] = "Convertito $tailwind β†’ $bootstrap"; } } // 5. Fix div con classi specifiche $content = preg_replace('/
/', '
', $content); $content = preg_replace('/
/', '
', $content); // Salva solo se ci sono stati cambiamenti if ($content !== $originalContent) { file_put_contents($filePath, $content); return $changes; } return []; } // Trova tutti i file blade che necessitano correzione $bladeFiles = findBladeFiles($basePath); // Filtra solo i file che hanno problemi di layout obsoleto $problematicFiles = []; foreach ($bladeFiles as $file) { $content = file_get_contents($file); if ( preg_match('/]*>/', $content) || preg_match('/@extends\([\'"]admin\.layouts\.main[\'"]/', $content) ) { $problematicFiles[] = $file; } } echo "🎯 Trovati " . count($problematicFiles) . " file da correggere\n\n"; // Processa ogni file foreach ($problematicFiles as $file) { $relativePath = str_replace($basePath . '/', '', $file); try { // Backup del file if (backupFile($file, $backupPath, $basePath)) { echo "πŸ’Ύ Backup: $relativePath\n"; // Applica le correzioni $changes = fixFile($file); if (!empty($changes)) { echo "βœ… Corretto: $relativePath\n"; foreach ($changes as $change) { echo " └─ $change\n"; } $fixed++; } else { echo "ℹ️ Nessuna modifica: $relativePath\n"; } } else { echo "❌ Errore backup: $relativePath\n"; $errors++; } } catch (Exception $e) { echo "❌ Errore: $relativePath - " . $e->getMessage() . "\n"; $errors++; } echo "\n"; } // Riepilogo finale echo str_repeat("=", 50) . "\n"; echo "πŸ“Š RIEPILOGO CORREZIONI\n"; echo str_repeat("=", 50) . "\n"; echo "βœ… File corretti: $fixed\n"; echo "❌ Errori: $errors\n"; echo "πŸ“ Backup salvato in: $backupPath\n\n"; if ($fixed > 0) { echo "πŸŽ‰ Correzioni applicate con successo!\n"; echo "πŸ“‹ Passi successivi:\n"; echo "1. Verifica che le pagine funzionino correttamente\n"; echo "2. Testa la navigazione e i form\n"; echo "3. Se tutto Γ¨ ok, rimuovi la cartella di backup\n"; echo "4. Se ci sono problemi, ripristina dal backup\n\n"; echo "πŸ”§ Per ripristinare dal backup:\n"; echo "cp -r $backupPath/* $basePath/\n\n"; } else { echo "ℹ️ Nessun file necessitava correzioni automatiche.\n"; } echo "✨ Processo completato!\n";