File manager - Edit - /var/www/html/portalHomolog/app/Console/Commands/RollbackImportLegislacaoCommand.php
Back
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; class RollbackImportLegislacaoCommand extends Command { protected $signature = 'legislacao:rollback-import {--force : Executa sem pedir confirmacao}'; protected $description = 'Remove todos os dados importados do modulo de legislacao.'; public function handle(): int { if ( !$this->option('force') && !$this->confirm('ATENCAO: todos os dados de legislacao serao APAGADOS. Deseja continuar?') ) { $this->info('Rollback cancelado.'); return self::SUCCESS; } $tables = [ 'legislacao_portaria_retificacao', 'legislacao_portaria_acao', 'legislacao_portaria', 'legislacao_retificacao', 'legislacao_acao', 'legislacao_categoria_associada', 'legislacao', 'legislacao_categoria', 'legislacao_tipo', 'legislacao_autor', 'legislacao_autor_cargo', ]; try { $counts = []; foreach ($tables as $table) { $counts[$table] = DB::table($table)->count(); } DB::statement('SET FOREIGN_KEY_CHECKS=0'); foreach ($tables as $table) { DB::table($table)->truncate(); } DB::statement('SET FOREIGN_KEY_CHECKS=1'); $rows = []; foreach ($counts as $table => $count) { $rows[] = [$table, $count]; } $this->table(['Tabela', 'Registros removidos'], $rows); $this->newLine(); $this->info('Rollback de legislacao concluido com sucesso!'); return self::SUCCESS; } catch (\Throwable $e) { DB::statement('SET FOREIGN_KEY_CHECKS=1'); $this->error('Rollback falhou: ' . $e->getMessage()); return self::FAILURE; } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings