File manager - Edit - /var/www/html/homologBancodetalentos/app/Console/Commands/TalentBankHomologSetupCommand.php
Back
<?php namespace App\Console\Commands; use App\Support\TalentBank\LegacySqlDumpSession; use Database\Seeders\TalentBankSeeder; use Illuminate\Console\Command; use Throwable; class TalentBankHomologSetupCommand extends Command { protected $signature = 'talent-bank:homolog-setup {--sql-dump= : Dump SIATI (.sql). Padrão: TALENT_BANK_LEGACY_SQL_DUMP} {--schema-only : Apenas migrate + seeders (sem import legado)} {--skip-seed : Não executa TalentBankSeeder} {--skip-dry-run : Pula dry-run pré/pós} {--skip-validate : Não executa validate-migration ao final} {--force : Sem confirmação interativa}'; protected $description = 'Setup homolog BT via dump SQL: schema, seeders, dry-run, migrate e validação.'; private ?LegacySqlDumpSession $dumpSession = null; public function handle(): int { $this->banner(); if (! $this->option('force') && ! $this->confirm('Executar setup completo do Banco de Talentos?', false)) { $this->line('Cancelado.'); return self::SUCCESS; } $steps = [ ['migrate --force', fn () => $this->call('migrate', ['--force' => true])], ]; if (! $this->option('skip-seed')) { $steps[] = ['db:seed TalentBankSeeder', fn () => $this->call('db:seed', [ '--class' => TalentBankSeeder::class, '--force' => true, ])]; } if (! $this->option('schema-only')) { try { $dumpPath = $this->resolveSqlDumpPath(); } catch (Throwable $e) { $this->error($e->getMessage()); return self::FAILURE; } $legacyConn = LegacySqlDumpSession::LEGACY_CONNECTION; $dryRunReportPre = storage_path('app/bt_dry_run_pre_'.now()->format('Y-m-d_His').'.json'); $dryRunReportPost = storage_path('app/bt_dry_run_post_'.now()->format('Y-m-d_His').'.json'); $migrateReport = storage_path('app/bt_migrate_'.now()->format('Y-m-d_His').'.json'); $steps[] = ['import dump SQL', fn () => $this->importDump($dumpPath)]; if (! $this->option('skip-dry-run')) { $steps[] = ['legacy-dry-run (pré)', fn () => $this->call('talent-bank:legacy-dry-run', [ '--legacy-connection' => $legacyConn, '--report' => $dryRunReportPre, ])]; } $steps[] = ['legacy-migrate', fn () => $this->call('talent-bank:legacy-migrate', [ '--force' => true, '--domain' => 'all', '--legacy-connection' => $legacyConn, '--report' => $migrateReport, ])]; if (! $this->option('skip-dry-run')) { $steps[] = ['legacy-dry-run (pós)', fn () => $this->call('talent-bank:legacy-dry-run', [ '--legacy-connection' => $legacyConn, '--report' => $dryRunReportPost, ])]; } $steps[] = ['cleanup dump temp', fn () => $this->cleanupDump()]; } $steps[] = ['optimize + cache', fn () => $this->warmCaches()]; $steps[] = ['validate-migration', fn () => ($this->option('skip-validate') || $this->option('schema-only')) ? self::SUCCESS : $this->call('talent-bank:validate-migration')]; foreach ($steps as [$label, $runner]) { $this->newLine(); $this->info("── {$label} ──"); $code = $runner(); if ($code !== self::SUCCESS) { $this->cleanupDump(); $this->error("Falhou em: {$label}"); return self::FAILURE; } } $this->newLine(); $this->info('Setup concluído. Confira portal e admin PAM no browser.'); return self::SUCCESS; } private function importDump(string $dumpPath): int { $this->dumpSession = new LegacySqlDumpSession($dumpPath); try { $this->dumpSession->ensureImported(function (string $step, string $message): void { $this->line(" [{$step}] {$message}"); }); } catch (Throwable $e) { $this->error('Falha ao importar dump: '.$e->getMessage()); return self::FAILURE; } return self::SUCCESS; } private function cleanupDump(): int { if ($this->dumpSession !== null) { $this->dumpSession->cleanup(); $this->dumpSession = null; $this->line('Banco temporário do dump removido.'); } return self::SUCCESS; } private function resolveSqlDumpPath(): string { $opt = $this->option('sql-dump'); if (is_string($opt) && trim($opt) !== '') { return LegacySqlDumpSession::resolvePath(trim($opt)); } return LegacySqlDumpSession::resolvePath((string) config('talent_bank_legacy_import.sql_dump')); } private function banner(): void { $this->newLine(); $this->line('╔══════════════════════════════════════════════════════╗'); $this->line('║ Setup Homolog BT — migração via dump SQL ║'); $this->line('╚══════════════════════════════════════════════════════╝'); $this->newLine(); if ($this->option('schema-only')) { $this->line(' Modo: schema + seeders (sem dados legados)'); return; } try { $dump = $this->resolveSqlDumpPath(); $this->line(" Dump: {$dump}"); } catch (Throwable) { $this->line(' Dump: (não configurado — defina TALENT_BANK_LEGACY_SQL_DUMP)'); } $db = config('database.connections.'.config('database.default').'.database'); $this->line(" Banco alvo: {$db}"); } private function warmCaches(): int { $this->call('optimize:clear'); $this->call('config:cache'); $this->call('route:cache'); $this->call('view:cache'); return self::SUCCESS; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings