option('action');
$this->info("π Ricerca view duplicate in tutto il sistema...");
$this->newLine();
// Directory principali da controllare
$searchPaths = [
base_path('resources/views'),
base_path('_BACKUP_OLD_netgescon-laravel_INACTIVE'),
base_path('_BACKUP_OLD_netgescon_INACTIVE'),
];
$viewFiles = [];
$duplicates = [];
// Raccoglie tutti i file .blade.php
foreach ($searchPaths as $basePath) {
if (!File::isDirectory($basePath)) continue;
$this->line("π Scansione: " . str_replace(base_path(), '', $basePath));
$files = File::allFiles($basePath);
foreach ($files as $file) {
if ($file->getExtension() === 'php' && str_ends_with($file->getFilename(), '.blade.php')) {
$relativePath = str_replace($basePath, '', $file->getPathname());
$filename = $file->getFilename();
if (!isset($viewFiles[$filename])) {
$viewFiles[$filename] = [];
}
$viewFiles[$filename][] = [
'full_path' => $file->getPathname(),
'relative_path' => $relativePath,
'base_path' => str_replace(base_path() . '/', '', $basePath),
'size' => $file->getSize(),
'modified' => filemtime($file->getPathname())
];
}
}
}
// Trova duplicati
foreach ($viewFiles as $filename => $locations) {
if (count($locations) > 1) {
$duplicates[$filename] = $locations;
}
}
if (empty($duplicates)) {
$this->info("β
Nessuna view duplicata trovata!");
return;
}
$this->warn("β οΈ Trovate " . count($duplicates) . " view duplicate:");
$this->newLine();
foreach ($duplicates as $filename => $locations) {
$this->line("π {$filename} (" . count($locations) . " copie):");
// Ordina per data di modifica (piΓΉ recente prima)
usort($locations, function ($a, $b) {
return $b['modified'] - $a['modified'];
});
foreach ($locations as $index => $location) {
$status = $index === 0 ? 'β
ATTIVA (piΓΉ recente)' : 'β DUPLICATA';
$date = date('d/m/Y H:i', $location['modified']);
$size = number_format($location['size'] / 1024, 2) . ' KB';
$this->line(" β’ {$location['base_path']}{$location['relative_path']}");
$this->line(" {$status} | {$date} | {$size}");
if ($action === 'move' && $index > 0) {
$this->moveDuplicateFile($location);
} elseif ($action === 'delete' && $index > 0) {
$this->deleteDuplicateFile($location);
}
}
$this->newLine();
}
if ($action === 'list') {
$this->newLine();
$this->info("π‘ Opzioni disponibili:");
$this->line(" β’ --action=move - Sposta i duplicati in una directory _DUPLICATES");
$this->line(" β’ --action=delete - Elimina i duplicati (ATTENZIONE!)");
}
}
private function moveDuplicateFile($location)
{
$duplicatesDir = base_path('_DUPLICATES_MOVED');
if (!File::isDirectory($duplicatesDir)) {
File::makeDirectory($duplicatesDir, 0755, true);
}
$targetPath = $duplicatesDir . '/' . $location['base_path'] . $location['relative_path'];
$targetDir = dirname($targetPath);
if (!File::isDirectory($targetDir)) {
File::makeDirectory($targetDir, 0755, true);
}
try {
File::move($location['full_path'], $targetPath);
$this->line(" β Spostato in: _DUPLICATES_MOVED/{$location['base_path']}{$location['relative_path']}");
} catch (\Exception $e) {
$this->error(" β Errore spostamento: " . $e->getMessage());
}
}
private function deleteDuplicateFile($location)
{
try {
File::delete($location['full_path']);
$this->line(" ποΈ Eliminato");
} catch (\Exception $e) {
$this->error(" β Errore eliminazione: " . $e->getMessage());
}
}
}