[#2] some progress
This commit is contained in:
@@ -13,6 +13,8 @@ use App\Models\ItemToFetchJobs;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\Network;
|
||||
use App\Models\Person;
|
||||
use App\Models\ProductionCompany;
|
||||
use App\Models\ProductionCountry;
|
||||
use App\Models\Season;
|
||||
use App\Models\Show;
|
||||
use App\Models\ShowAlternativeTitle;
|
||||
@@ -60,18 +62,23 @@ class ShowProcessingService implements ProcessingInterface
|
||||
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
if ($show) {
|
||||
echo "+";
|
||||
return;
|
||||
}
|
||||
|
||||
echo ".";
|
||||
$tmdbShow['slug'] = Str::slug($tmdbShow['name'].'-'.$tmdbShow['tmdb_id']);
|
||||
$tmdbShow['first_air_date'] = $tmdbShow['first_air_date'] ? new \DateTime($tmdbShow['first_air_date']) : null;
|
||||
$tmdbShow['last_air_date'] = $tmdbShow['last_air_date'] ? new \DateTime($tmdbShow['last_air_date']) : null;
|
||||
$tmdbShow['episode_run_time'] = reset($tmdbShow['episode_run_time']);
|
||||
$tmdbShow['episode_run_time'] = reset($tmdbShow['episode_run_time']);
|
||||
$tmdbShow['episode_run_time'] = is_array($tmdbShow['episode_run_time']) ? reset($tmdbShow['episode_run_time']) : $tmdbShow['episode_run_time'];
|
||||
$tmdbShow['languages'] = json_encode($tmdbShow['languages']);
|
||||
$tmdbShow['number_of_episodes'] = $tmdbShow['number_of_episodes'] ?? 0;
|
||||
$tmdbShow['origin_country'] = is_array($tmdbShow['origin_country']) ? reset($tmdbShow['origin_country']) : $tmdbShow['origin_country'];
|
||||
|
||||
$show = Show::create($tmdbShow);
|
||||
try {
|
||||
$show = Show::create($tmdbShow);
|
||||
} catch (\Throwable $e) {
|
||||
dd($e, $tmdbShow);
|
||||
}
|
||||
|
||||
if (!empty($tmdbShow['seasons'])) {
|
||||
$this->processSeasons($show, $tmdbShow['seasons']);
|
||||
@@ -86,8 +93,16 @@ class ShowProcessingService implements ProcessingInterface
|
||||
}
|
||||
|
||||
// @todo process created_by
|
||||
// @todo process production countries
|
||||
// @todo process production companies
|
||||
|
||||
if (!empty($tmdbShow['production_countries'])) {
|
||||
//dd('123');
|
||||
$this->processProductionCountries($item, $tmdbShow['production_countries']);
|
||||
}
|
||||
|
||||
if (!empty($tmdbShow['production_companies'])) {
|
||||
//dd('456');
|
||||
$this->processProductionCompanies($item, $tmdbShow['production_companies']);
|
||||
}
|
||||
|
||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_DETAILS);
|
||||
}
|
||||
@@ -794,4 +809,54 @@ class ShowProcessingService implements ProcessingInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function processProductionCompanies($item, array $productionCompanies)
|
||||
{
|
||||
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
foreach ($productionCompanies as $productionCompany) {
|
||||
$existingProductionCompany = ProductionCompany::where('tmdb_id', $productionCompany['id'])->first();
|
||||
|
||||
if (!$existingProductionCompany) {
|
||||
$existingProductionCompany = ProductionCompany::create([
|
||||
'tmdb_id' => $productionCompany['id'],
|
||||
'logo_path' => $productionCompany['logo_path'],
|
||||
'name' => $productionCompany['name'],
|
||||
'origin_country' => $productionCompany['origin_country'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($show->whereHas('productionCompanies', function ($query) use ($existingProductionCompany) {
|
||||
$query->where('production_company_id', '=', $existingProductionCompany->id);
|
||||
})->exists()) {
|
||||
return;
|
||||
} else {
|
||||
$show->productionCompanies()->attach($existingProductionCompany);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function processProductionCountries($item, array $productionCountries)
|
||||
{
|
||||
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
|
||||
|
||||
foreach ($productionCountries as $productionCountry) {
|
||||
$existingProductionCountry = ProductionCountry::where('iso_3166', $productionCountry['iso_3166_1'])->first();
|
||||
|
||||
if (!$existingProductionCountry) {
|
||||
$existingProductionCountry = ProductionCountry::create([
|
||||
'iso_3166' => $productionCountry['iso_3166_1'],
|
||||
'name' => $productionCountry['name'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($show->whereHas('productionCountries', function ($query) use ($existingProductionCountry) {
|
||||
$query->where('production_country_id', '=', $existingProductionCountry->id);
|
||||
})->exists()) {
|
||||
return;
|
||||
} else {
|
||||
$show->productionCountries()->attach($existingProductionCountry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user