[#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();
@@ -0,0 +1,35 @@
<?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('external_ids', function (Blueprint $table) {
$table->id();
$table->integer('entity_id');
$table->string('entity_type');
$table->integer('tmdb_id');
$table->string('imdb_id');
$table->string('wikidata_id');
$table->string('facebook_id');
$table->string('instagram_id');
$table->string('twitter_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('external_ids');
}
};