diff --git a/app/Models/ExternalId.php b/app/Models/ExternalId.php new file mode 100644 index 0000000..5f162eb --- /dev/null +++ b/app/Models/ExternalId.php @@ -0,0 +1,22 @@ +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(); diff --git a/database/migrations/2024_12_30_010725_create_external_ids_table.php b/database/migrations/2024_12_30_010725_create_external_ids_table.php new file mode 100644 index 0000000..563305b --- /dev/null +++ b/database/migrations/2024_12_30_010725_create_external_ids_table.php @@ -0,0 +1,35 @@ +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'); + } +};