2024-12-30 01:51:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands\ItemProcessing;
|
|
|
|
|
|
|
|
|
|
use App\Models\ItemToFetch;
|
2025-01-27 22:40:26 +02:00
|
|
|
use App\Models\ItemToFetchJobs;
|
|
|
|
|
use App\Models\Movie;
|
2024-12-30 01:51:28 +02:00
|
|
|
use App\Service\MediaProcessing\FactoryService;
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
|
|
class FetchItemDataCommand extends Command
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $signature = 'processing:fetch-item-data {type=movie} {batch=50} {job=Details}';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = 'Command description';
|
|
|
|
|
private FactoryService $factoryService;
|
|
|
|
|
|
|
|
|
|
public function __construct(FactoryService $factoryService)
|
|
|
|
|
{
|
|
|
|
|
$this->factoryService = $factoryService;
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$type = $this->argument('type');
|
|
|
|
|
$batch = $this->argument('batch');
|
|
|
|
|
$job = $this->argument('job');
|
|
|
|
|
|
|
|
|
|
$items = $this->getBatch($type, $batch, $job);
|
|
|
|
|
|
|
|
|
|
$this->processItems($items, $job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getBatch(string $type, int $batch, string $job)
|
|
|
|
|
{
|
2025-01-27 22:40:26 +02:00
|
|
|
// if job <> Details the movie in movie table should exist
|
|
|
|
|
$query = ItemToFetch::whereHas('jobs', function($query) use ($job){
|
2025-01-26 21:36:05 +02:00
|
|
|
return $query->where('jobs', '<>', null)->whereRaw('FIND_IN_SET(?, jobs)', [$job]);
|
2025-01-27 22:40:26 +02:00
|
|
|
})->with(['jobs']);
|
|
|
|
|
|
|
|
|
|
if ($job !== ItemToFetchJobs::JOB_DETAILS) {
|
|
|
|
|
$query = $query->join('movies', 'movies.tmdb_id', '=', 'items_to_fetch.tmdb_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query
|
2024-12-30 01:51:28 +02:00
|
|
|
->where('type', $type)
|
|
|
|
|
->take($batch)
|
|
|
|
|
->get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function processItems(\Illuminate\Database\Eloquent\Collection $items, $job)
|
|
|
|
|
{
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$this->processItem($item, $job);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function processItem($item, $job)
|
|
|
|
|
{
|
|
|
|
|
$this->factoryService->process($item, $job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|