Skip to content

Commit

Permalink
Merge pull request #125 from UNICEF01/testing
Browse files Browse the repository at this point in the history
Acréscimo de novo comando para Reindex de escolas específicas de acor…
  • Loading branch information
manoelsouzaunicef committed Jul 8, 2019
2 parents 55e5b90 + 5f0faa3 commit 32832c7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
51 changes: 51 additions & 0 deletions app/Console/Commands/ReindexSchoolById.php
@@ -0,0 +1,51 @@
<?php

namespace BuscaAtivaEscolar\Console\Commands;


use BuscaAtivaEscolar\School;
use BuscaAtivaEscolar\Search\Search;
use DB;
use Illuminate\Support\Str;
use PDO;

class ReindexSchoolById extends Command {

protected $signature = 'maintenance:reindex_school_by_id';
protected $description = 'Forces a specific schools to be reindex in ElasticSearch';

public function handle(Search $search) {

$schoolID = $this->ask("Enter the school ID: ");

$pdo = DB::getPDO();
$mock = new School();

$stmt = $pdo->prepare("SELECT * FROM schools where schools.id = ".$schoolID);
$stmt->execute();

$total = $stmt->rowCount();
$indexed = 0;

if(!$total) {
$this->error("No rows found!");
return;
}

while(($data = $stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$mock->fill($data);
$search->index($mock);
$indexed++;


$progress = "[ " . sprintf("%.3f", (($indexed / $total) * 100)) . " % ] \t";
$memory_usage = "\t mem=" . sprintf("%.2f", (memory_get_usage() / 1024) / 1024) . " MB \t peak=" . sprintf("%.2f", (memory_get_peak_usage() / 1024) / 1024) .' MB';
$short_name = str_pad(Str::limit($mock->name, 16), 20, " ");
$this->comment("{$progress} Reindexed: {$mock->id} -> {$mock->uf} / {$short_name} \t {$memory_usage}");
}

$this->comment("{$progress} Indexing completed! ({$indexed} out of {$total} indexed) {$memory_usage}");

}

}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Expand Up @@ -33,7 +33,8 @@ class Kernel extends ConsoleKernel
Commands\AddAndCheckGroupIntoNewCase::class,
Commands\AddPriorityTenantNewMotive::class,
Commands\ForceObligatorinessEducationReason::class,
Commands\DisplayPrimaryGroupsUnrelatedWithAllAlerts::class
Commands\DisplayPrimaryGroupsUnrelatedWithAllAlerts::class,
Commands\ReindexSchoolById::class
];

/**
Expand Down

0 comments on commit 32832c7

Please sign in to comment.