Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from UNICEF01/testing
Acréscimo de novo comando para Reindex de escolas específicas de acor…
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters