- Fix vider la barre de recherche quand on clique sur "Réinitialiser" - Fix script index ElasticMedia + ajout condition sur l'existence d'un index - Ajout de la requete Elasticsearch dans MediaController
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Media;
|
|
|
|
class reindexElasticMedia extends Command
|
|
{
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'medias:reindex';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Reindex la base médias dans Elasticsearch';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Reindexation de la base médias dans Elasticsearch...');
|
|
if (Media::indexExists())
|
|
Media::deleteIndex();
|
|
Media::createIndex();
|
|
$medias = Media::all();
|
|
$bar = $this->output->createProgressBar(count($medias));
|
|
$bar->start();
|
|
foreach ($medias as $media) {
|
|
// ---- index le media dans Elasticsearch
|
|
$media->addToIndex();
|
|
$bar->advance();
|
|
}
|
|
$bar->finish();
|
|
$this->line("");
|
|
$this->info('Fin du traitement');
|
|
}
|
|
}
|