102 lines
3.5 KiB
PHP
102 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class CleanDeprecatedLayouts extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'netgescon:clean-layouts {--dry-run : Show what would be changed without making changes} {--force : Force changes without confirmation}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Pulisce i layout deprecati e forza l\'uso del layout attivo di NetGescon';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$dryRun = $this->option('dry-run');
|
|
$force = $this->option('force');
|
|
|
|
$activeLayout = config('netgescon.active_layout', 'admin.layouts.netgescon');
|
|
$deprecatedLayouts = config('netgescon.deprecated_layouts', []);
|
|
|
|
$this->info("🔍 Scansione file Blade per layout deprecati...");
|
|
$this->info("Layout attivo: {$activeLayout}");
|
|
$this->info("Layout deprecati: " . implode(', ', $deprecatedLayouts));
|
|
|
|
$files = File::allFiles(resource_path('views'));
|
|
$changedFiles = [];
|
|
$totalChanges = 0;
|
|
|
|
foreach ($files as $file) {
|
|
if ($file->getExtension() === 'php' && str_ends_with($file->getFilename(), '.blade.php')) {
|
|
$content = File::get($file->getPathname());
|
|
$originalContent = $content;
|
|
|
|
foreach ($deprecatedLayouts as $deprecated) {
|
|
$pattern = "/@extends\s*\(\s*['\"]" . preg_quote($deprecated, '/') . "['\"]\s*\)/";
|
|
if (preg_match($pattern, $content)) {
|
|
$replacement = "@extends('{$activeLayout}')";
|
|
$content = preg_replace($pattern, $replacement, $content);
|
|
|
|
if (!$dryRun) {
|
|
File::put($file->getPathname(), $content);
|
|
}
|
|
|
|
$relativePath = str_replace(base_path() . '/', '', $file->getPathname());
|
|
$changedFiles[] = $relativePath;
|
|
$totalChanges++;
|
|
|
|
if ($dryRun) {
|
|
$this->line("🔄 [DRY-RUN] {$relativePath}: {$deprecated} → {$activeLayout}");
|
|
} else {
|
|
$this->line("✅ {$relativePath}: {$deprecated} → {$activeLayout}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($totalChanges === 0) {
|
|
$this->info("✨ Nessun layout deprecato trovato. Tutto pulito!");
|
|
return;
|
|
}
|
|
|
|
if ($dryRun) {
|
|
$this->warn("📋 [DRY-RUN] Sarebbero stati modificati {$totalChanges} file(s).");
|
|
$this->info("💡 Rimuovi --dry-run per applicare le modifiche.");
|
|
} else {
|
|
$this->info("🎉 Modificati {$totalChanges} file(s) con successo!");
|
|
|
|
// Pulisce le cache
|
|
$this->info("🧹 Pulizia cache Laravel...");
|
|
$this->call('view:clear');
|
|
$this->call('config:clear');
|
|
$this->call('route:clear');
|
|
|
|
$this->info("✅ Pulizia completata!");
|
|
}
|
|
|
|
// Mostra riassunto
|
|
if (!empty($changedFiles)) {
|
|
$this->newLine();
|
|
$this->info("📁 File modificati:");
|
|
foreach ($changedFiles as $file) {
|
|
$this->line(" • {$file}");
|
|
}
|
|
}
|
|
}
|
|
}
|