Prioritize relative ids for episodes, as external ids reported from backends is often incorrect for episodes.

This commit is contained in:
Abdulmhsen B. A. A
2022-06-24 19:30:54 +03:00
parent 318f714c9d
commit d016fa613c
3 changed files with 35 additions and 11 deletions

View File

@@ -527,7 +527,19 @@ final class DirectMapper implements ImportInterface
return $entity->id;
}
foreach ([...$entity->getRelativePointers(), ...$entity->getPointers()] as $key) {
// -- Prioritize relative ids for episodes, External ids are often incorrect for episodes.
if (true === $entity->isEpisode()) {
foreach ($entity->getRelativePointers() as $key) {
$lookup = $key . '/' . $entity->type;
if (null !== ($this->pointers[$lookup] ?? null)) {
return $this->pointers[$lookup];
}
}
}
// -- look up movies based on guid.
// -- if episode didn't have any match using relative id then fallback to external ids.
foreach ($entity->getPointers() as $key) {
$lookup = $key . '/' . $entity->type;
if (null !== ($this->pointers[$lookup] ?? null)) {
return $this->pointers[$lookup];

View File

@@ -451,7 +451,19 @@ final class MemoryMapper implements ImportInterface
return self::GUID . $entity->id;
}
foreach ([...$entity->getRelativePointers(), ...$entity->getPointers()] as $key) {
// -- Prioritize relative ids for episodes, External ids are often incorrect for episodes.
if (true === $entity->isEpisode()) {
foreach ($entity->getRelativePointers() as $key) {
$lookup = $key . '/' . $entity->type;
if (null !== ($this->pointers[$lookup] ?? null)) {
return $this->pointers[$lookup];
}
}
}
// -- look up movies based on guid.
// -- if episode didn't have any match using relative id then fallback to external ids.
foreach ($entity->getPointers() as $key) {
$lookup = $key . '/' . $entity->type;
if (null !== ($this->pointers[$lookup] ?? null)) {
return $this->pointers[$lookup];

View File

@@ -465,15 +465,6 @@ final class PDOAdapter implements StorageInterface
'type' => $entity->type,
];
foreach ($entity->getGuids() as $key => $val) {
if (empty($val)) {
continue;
}
$guids[] = "JSON_EXTRACT(" . iFace::COLUMN_GUIDS . ",'$.{$key}') = :g_{$key}";
$cond['g_' . $key] = $val;
}
$sqlEpisode = '';
if (true === $entity->isEpisode()) {
@@ -492,6 +483,15 @@ final class PDOAdapter implements StorageInterface
}
}
foreach ($entity->getGuids() as $key => $val) {
if (empty($val)) {
continue;
}
$guids[] = "JSON_EXTRACT(" . iFace::COLUMN_GUIDS . ",'$.{$key}') = :g_{$key}";
$cond['g_' . $key] = $val;
}
if (empty($guids)) {
return null;
}