2021-06-03 16:50:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use App\Models\Media;
|
2022-04-20 15:23:31 +02:00
|
|
|
use Illuminate\Console\Command;
|
2021-06-03 16:50:50 +02:00
|
|
|
|
2022-04-20 15:23:31 +02:00
|
|
|
class ReindexElasticOneMedia extends Command
|
2021-06-03 16:50:50 +02:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2022-06-20 14:57:58 +02:00
|
|
|
protected $signature = 'media:reindexone {media_id}';
|
2021-06-03 16:50:50 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = 'Command description';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
2022-06-20 14:57:58 +02:00
|
|
|
$mediaID = \strval($this->argument('media_id'));
|
|
|
|
|
$this->info("Reindexation du media $mediaID dans Elasticsearch...");
|
|
|
|
|
/** @var \App\Models\Media */
|
|
|
|
|
if (!($media = Media::withTrashed()->find($this->argument('media_id')))) {
|
|
|
|
|
$this->info("Pas de media $mediaID");
|
2021-06-03 16:50:50 +02:00
|
|
|
}
|
2022-06-20 14:57:58 +02:00
|
|
|
/** @throws \RuntimeException */
|
|
|
|
|
$media->addToElasticSearch();
|
|
|
|
|
$this->info("Media ID '$mediaID' Ajouté");
|
2021-06-03 16:50:50 +02:00
|
|
|
}
|
|
|
|
|
}
|