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

40 lines
960 B
PHP
Raw 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 = 'medias:reindexone {media_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2022-04-19 16:07:27 +02:00
$this->info('Reindexation du media ' . $this->argument('media_id') . ' dans Elasticsearch...');
$media = Media::withTrashed()->find($this->argument('media_id'));
2021-06-03 16:50:50 +02:00
$esExist = Media::searchByQuery(array('match' => array('arcadia_id' => "$media->arcadia_id")));
if ($esExist->totalHits() > 0) {
$media->removeFromIndex();
}
$media->addToIndex();
}
}