Merge pull request #2389 from Roardom/fix-wrong-director

(Fix) Wrong director
This commit is contained in:
HDVinnie
2022-12-18 18:04:10 -05:00
committed by GitHub
7 changed files with 128 additions and 5 deletions

View File

@@ -97,7 +97,12 @@ class ProcessMovieJob implements ShouldQueue
if (isset($this->movie['credits']['crew'])) {
foreach ($this->movie['credits']['crew'] as $crew) {
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))->movie()->syncWithoutDetaching([$this->movie['id']]);
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))
->movie()
->syncWithoutDetaching([$this->movie['id'] => [
'department' => $crew['department'] ?? null,
'job' => $crew['job'] ?? null,
]]);
}
}

View File

@@ -107,7 +107,12 @@ class ProcessTvJob implements ShouldQueue
if (isset($this->tv['credits']['crew'])) {
foreach ($this->tv['credits']['crew'] as $crew) {
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))->tv()->syncWithoutDetaching([$this->tv['id']]);
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))
->tv()
->syncWithoutDetaching([$this->tv['id'] => [
'department' => $crew['department'] ?? null,
'job' => $crew['job'] ?? null,
]]);
}
}
@@ -168,7 +173,12 @@ class ProcessTvJob implements ShouldQueue
foreach ($season['credits']['crew'] as $crew) {
if (isset($crew['id'])) {
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))->season()->syncWithoutDetaching([$season['id']]);
Crew::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))
->season()
->syncWithoutDetaching([$season['id'] => [
'department' => $season['department'] ?? null,
'job' => $season['job'] ?? null,
]]);
Person::updateOrCreate(['id' => $crew['id']], $tmdb->person_array($crew))->tv()->syncWithoutDetaching([$this->id]);
}
}

View File

@@ -56,6 +56,6 @@ class Season extends Model
public function crew(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Crew::class);
return $this->belongsToMany(Crew::class, 'crew_season', 'person_id', 'season_id');
}
}

View File

@@ -0,0 +1,34 @@
<?php
use App\Models\Movie;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('crew_movie', function (Blueprint $table) {
$table->string('department')->nullable();
$table->string('job')->nullable();
});
foreach (Movie::all() as $movie) {
$crew = (new \App\Services\Tmdb\Client\Movie($movie->id))->get_crew();
if (isset($crew)) {
foreach ($crew as $crewMember) {
$movie->crew()->updateExistingPivot($crewMember['id'], [
'department' => $crewMember['department'],
'job' => $crewMember['job'],
]);
}
}
}
}
};

View File

@@ -0,0 +1,34 @@
<?php
use App\Models\Tv;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('crew_tv', function (Blueprint $table) {
$table->string('department')->nullable();
$table->string('job')->nullable();
});
foreach (Tv::all() as $tv) {
$data = (new \App\Services\Tmdb\Client\TV($tv->id))->getData();
if (isset($data['credits']['crew'])) {
foreach ($data['credits']['crew'] as $crewMember) {
$tv->crew()->updateExistingPivot($crewMember['id'], [
'department' => $crewMember['department'],
'job' => $crewMember['job'],
]);
}
}
}
}
};

View File

@@ -0,0 +1,40 @@
<?php
use App\Models\Season;
use App\Models\Tv;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('crew_season', function (Blueprint $table) {
$table->string('department')->nullable();
$table->string('job')->nullable();
});
foreach (Tv::all() as $tv) {
$data = (new \App\Services\Tmdb\Client\TV($tv->id))->getData();
foreach ($data['seasons'] as $season) {
$season = (new \App\Services\Tmdb\Client\Season($tv->id, \sprintf('%02d', $season['season_number'])))->getData();
$seasonModel = Season::find($season['id']);
if (isset($season['credits']['crew'])) {
foreach ($season['credits']['crew'] as $crewMember) {
$seasonModel->crew()->updateExistingPivot($crewMember['id'], [
'department' => $crewMember['department'],
'job' => $crewMember['job'],
]);
}
}
}
}
}
};

View File

@@ -49,7 +49,7 @@
<div class="movie-bottom">
<div class="movie-details">
@if(isset($meta->crew))
@if(!empty($directors = $meta->crew()->where('known_for_department' ,'=', 'Directing')->take(1)->get()))
@if(!empty($directors = $meta->crew()->wherePivot('department' ,'=', 'Directing')->take(1)->get()))
<span class="badge-user text-bold text-purple">
<i class="{{ config('other.font-awesome') }} fa-camera-movie"></i> Directors:
@foreach($directors as $director)