ldc-dam/app/Console/Commands/ReindexElasticOneMedia.php

42 lines
1,001 B
PHP
Raw Permalink Normal View History

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
*/
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()
{
$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
}
/** @throws \RuntimeException */
$media->addToElasticSearch();
$this->info("Media ID '$mediaID' Ajouté");
2021-06-03 16:50:50 +02:00
}
}