This commit is contained in:
2025-01-08 02:08:41 +02:00
parent 60ee3bb759
commit ddbfc95102
3 changed files with 68 additions and 0 deletions
+5
View File
@@ -70,4 +70,9 @@ class Show extends Model
{
return $this->belongsToMany(ContentRating::class, 'show_content_ratings', 'show_id', 'content_rating_id');
}
public function genres()
{
return $this->belongsToMany(Genre::class, 'show_genres', 'show_id', 'genre_id');
}
}
@@ -6,6 +6,7 @@ use App\Models\Comment;
use App\Models\ContentRating;
use App\Models\Episode;
use App\Models\ExternalId;
use App\Models\Genre;
use App\Models\Image;
use App\Models\ItemToFetch;
use App\Models\ItemToFetchJobs;
@@ -75,7 +76,12 @@ class ShowProcessingService implements ProcessingInterface
$this->processSeasons($show, $tmdbShow['seasons']);
}
if (!empty($tmdbShow['genres'])) {
$this->processGenres($item, $tmdbShow['genres']);
}
// @todo process genres
// @todo process created_by
// @todo process networks
// @todo process production countries
// @todo process production companies
@@ -728,4 +734,32 @@ class ShowProcessingService implements ProcessingInterface
return $itemToFetch;
}
private function processGenres($item, array $genres)
{
foreach ($genres as $tmdbGenre) {
$genre = Genre::where('name', $tmdbGenre['name'])
->where('tmdb_id', $tmdbGenre['id'])
->first();
if (!$genre) {
$genre = Genre::create([
'name' => $tmdbGenre['name'],
'slug' => Str::slug($tmdbGenre['name']),
'tmdb_id' => $tmdbGenre['id'],
'type' => Genre::TYPE_SHOW,
]);
}
$show = Show::where('tmdb_id', $item->tmdb_id)->first();
if ($show->whereHas('genres', function ($query) use ($genre) {
$query->where('tmdb_id', '=', $genre->tmdb_id);
})->exists()) {
return;
} else {
$show->genres()->attach($genre);
}
}
}
}
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('show_genres', function (Blueprint $table) {
$table->id();
$table->bigInteger('show_id');
$table->bigInteger('genre_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('show_genres');
}
};