progress
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Models\ItemToFetch;
|
||||
use App\Models\ItemToFetchJobs;
|
||||
use App\Models\Movie;
|
||||
use App\Service\MediaProcessing\FactoryService;
|
||||
use App\Service\MediaProcessing\MovieProcessingService;
|
||||
use App\Service\MediaProcessing\ShowProcessingService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FetchItemDataCommand extends Command
|
||||
@@ -15,7 +17,7 @@ class FetchItemDataCommand extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'processing:fetch-item-data {type=movie} {batch=50} {job=Details}';
|
||||
protected $signature = 'processing:fetch-item-data {type=movie} {batch=50} {job=Details} {tmdbId?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -36,42 +38,47 @@ class FetchItemDataCommand extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info("Start");
|
||||
|
||||
$type = $this->argument('type');
|
||||
$batch = $this->argument('batch');
|
||||
$job = $this->argument('job');
|
||||
$tmdbId = $this->argument('tmdbId');
|
||||
|
||||
$items = $this->getBatch($type, $batch, $job);
|
||||
$items = $this->getBatch($type, $batch, $job, $tmdbId);
|
||||
|
||||
$this->processItems($items, $job);
|
||||
$this->info("Processing ".count($items)." items of type `{$type}`.");
|
||||
|
||||
$this->processItems($items, $job, $type);
|
||||
|
||||
$this->info("Fin.");
|
||||
}
|
||||
|
||||
private function getBatch(string $type, int $batch, string $job)
|
||||
private function getBatch(string $type, int $batch, string $job, int $tmdbId = null)
|
||||
{
|
||||
// if job <> Details the movie in movie table should exist
|
||||
$query = ItemToFetch::whereHas('jobs', function($query) use ($job){
|
||||
return $query->where('jobs', '<>', null)->whereRaw('FIND_IN_SET(?, jobs)', [$job]);
|
||||
})->with(['jobs']);
|
||||
|
||||
if ($job !== ItemToFetchJobs::JOB_DETAILS) {
|
||||
$query = $query->join('movies', 'movies.tmdb_id', '=', 'items_to_fetch.tmdb_id');
|
||||
switch ($type){
|
||||
case ItemToFetch::TYPE_MOVIE:
|
||||
return MovieProcessingService::getBatch($batch, $job);
|
||||
case ItemToFetch::TYPE_TV_SERIES:
|
||||
return ShowProcessingService::getBatch($batch, $job, $tmdbId);
|
||||
}
|
||||
|
||||
return $query
|
||||
->where('type', $type)
|
||||
->take($batch)
|
||||
->get();
|
||||
}
|
||||
|
||||
private function processItems(\Illuminate\Database\Eloquent\Collection $items, $job)
|
||||
private function processItems(\Illuminate\Database\Eloquent\Collection $items, $job, $type)
|
||||
{
|
||||
$bar = $this->output->createProgressBar(count($items));
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->processItem($item, $job);
|
||||
$this->processItem($item, $job, $type);
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
}
|
||||
|
||||
private function processItem($item, $job)
|
||||
private function processItem($item, $job, $type)
|
||||
{
|
||||
$this->factoryService->process($item, $job);
|
||||
$this->factoryService->process($item, $job, $type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user