[#1] external ids

This commit is contained in:
2024-12-30 03:11:14 +02:00
parent fcca3d032c
commit 89f80b7937
3 changed files with 83 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ExternalId extends Model
{
public const TYPE_MOVIE = 'movie';
public const TYPE_SHOW = 'show';
protected $fillable = [
'entity_id',
'entity_type',
'tmdb_id',
'imdb_id',
'wikidata_id',
'facebook_id',
'instagram_id',
'twitter_id',
];
}
@@ -3,6 +3,7 @@
namespace App\Service\MediaProcessing;
use App\Models\Comment;
use App\Models\ExternalId;
use App\Models\Genre;
use App\Models\Image;
use App\Models\ItemToFetchJobs;
@@ -298,6 +299,31 @@ class MovieProcessingService implements ProcessingInterface
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_REVIEWS);
}
private function getExternalIds($item)
{
$externalIds = $this->moviesApi->getExternalIds($item->tmdb_id);
if (empty($externalIds)) {
return;
}
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
$externalId = ExternalId::where('entity_id', $movie->id)
->where('entity_type', ExternalId::TYPE_MOVIE)
->first();
if (!$externalId) {
$externalIds['tmdb_id'] = $externalIds['id'];
$externalIds['movie_id'] = $movie->id;
unset($externalIds['id']);
ExternalId::create($externalIds);
}
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_EXTERNAL_IDS);
}
private function processMovieCollection(int $movieId, $belongsToCollection)
{
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();