Skip to content

Commit

Permalink
Merge pull request #132 from UNICEF01/bug_alertas_travados#291
Browse files Browse the repository at this point in the history
Mudanca do tipo do campo do NIS na tabela Pesquisa e Comando para cor…
  • Loading branch information
manoelsouzaunicef committed Sep 5, 2019
2 parents e17b909 + bb19605 commit acb81e5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
65 changes: 65 additions & 0 deletions app/Console/Commands/FixErrorCasesInAlertStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace BuscaAtivaEscolar\Console\Commands;

use BuscaAtivaEscolar\CaseSteps\Alerta;
use BuscaAtivaEscolar\CaseSteps\Pesquisa;
use BuscaAtivaEscolar\Child;
use function foo\func;
use Illuminate\Console\Command;
use Log;

class FixErrorCasesInAlertStep extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'correcoes:casos_travados_etapa_alerta';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Corrigir erro dos casos que permanecem na etapa de Alerta e deveriam estar na etapa de Pesquisa, considerando a possibilidade de erros como falta de endereço e bairro (campos obrigatórios para aprovacao de um alerta)';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->comment("Iniciando correcoes");
$qtd_alerts = Child::where(['current_step_type' => 'BuscaAtivaEscolar\CaseSteps\Alerta', 'alert_status' => 'accepted'])->count();
$children = Child::where(['current_step_type' => 'BuscaAtivaEscolar\CaseSteps\Alerta', 'alert_status' => 'accepted'])->get();
foreach ($children as $child){
$alerta = Alerta::where('child_id', $child->id)->first();
$pesquisa = Pesquisa::where('child_id', $child->id)->first();

if( $alerta->nis == ""){ $alerta->nis = null; }

$child->current_step_id = $pesquisa->id;
$child->current_step_type = 'BuscaAtivaEscolar\CaseSteps\Pesquisa';

$pesquisa->setFields($alerta->toArray());

$alerta->save();
$pesquisa->save();
$child->save();
}
$this->comment("Finalizando correcoes dos ".$qtd_alerts." alertas");
}
}
4 changes: 3 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BuscaAtivaEscolar\Console;

use BuscaAtivaEscolar\Console\Commands\Command;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand Down Expand Up @@ -34,7 +35,8 @@ class Kernel extends ConsoleKernel
Commands\AddPriorityTenantNewMotive::class,
Commands\ForceObligatorinessEducationReason::class,
Commands\DisplayPrimaryGroupsUnrelatedWithAllAlerts::class,
Commands\ReindexSchoolById::class
Commands\ReindexSchoolById::class,
Commands\FixErrorCasesInAlertStep::class
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UpdateNisEtspCasePesquisa extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Schema::table('case_steps_pesquisa', function (Blueprint $table) {
$table->string('nis');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

}
}

0 comments on commit acb81e5

Please sign in to comment.