From c93629dea20804ddc7649a238e1f590ada85e9f6 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 11 Jul 2019 16:38:21 -0400 Subject: [PATCH] Show fewer sync errors by filtering common data disparity issues --- src/API/Anilist/MissingIdException.php | 19 +++++++++++ src/API/Anilist/Model.php | 9 +++-- src/Command/SyncLists.php | 47 ++++++++++++++++++-------- 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 src/API/Anilist/MissingIdException.php diff --git a/src/API/Anilist/MissingIdException.php b/src/API/Anilist/MissingIdException.php new file mode 100644 index 00000000..fb116a1e --- /dev/null +++ b/src/API/Anilist/MissingIdException.php @@ -0,0 +1,19 @@ + + * @copyright 2015 - 2018 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 4.1 + * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient + */ + +namespace Aviat\AnimeClient\API\Anilist; + +class MissingIdException extends \InvalidArgumentException {} \ No newline at end of file diff --git a/src/API/Anilist/Model.php b/src/API/Anilist/Model.php index 3e75f23a..6626cf18 100644 --- a/src/API/Anilist/Model.php +++ b/src/API/Anilist/Model.php @@ -124,10 +124,10 @@ final class Model $mediaId = $this->getMediaIdFromMalId($data['mal_id'], mb_strtoupper($type)); - if (empty($mediaId)) + /* if (empty($mediaId)) { throw new InvalidArgumentException('Media id missing'); - } + } */ if ($type === 'ANIME') { @@ -159,6 +159,11 @@ final class Model $createData = $data['data']; $mediaId = $this->getMediaIdFromMalId($data['mal_id'], strtoupper($type)); + if (empty($mediaId)) + { + throw new MissingIdException('No id mapping found'); + } + $createData['id'] = $mediaId; return $this->listItem->createFull($createData); diff --git a/src/Command/SyncLists.php b/src/Command/SyncLists.php index db689be7..dd05184f 100644 --- a/src/Command/SyncLists.php +++ b/src/Command/SyncLists.php @@ -16,11 +16,8 @@ namespace Aviat\AnimeClient\Command; -use Aviat\AnimeClient\API\{ - FailedResponseException, - JsonAPI, - ParallelAPIRequest -}; +use Aviat\AnimeClient\API\ +{Anilist\MissingIdException, FailedResponseException, JsonAPI, ParallelAPIRequest}; use Aviat\AnimeClient\API\Anilist\Transformer\{ AnimeListTransformer as AALT, MangaListTransformer as AMLT @@ -311,19 +308,19 @@ final class SyncLists extends BaseCommand { $anilistUpdateItems = []; $kitsuUpdateItems = []; - $malBlackList = ($type === 'anime') + /* $malBlackList = ($type === 'anime') ? [ 27821, // Fate/stay night: Unlimited Blade Works - Prologue 29317, // Saekano: How to Raise a Boring Girlfriend Prologue 30514, // Nisekoinogatari ] : [ 114638, // Cells at Work: Black - ]; + ]; */ $malIds = array_keys($anilistList); $kitsuMalIds = array_map('intval', array_column($kitsuList, 'malId')); $missingMalIds = array_diff($malIds, $kitsuMalIds); - $missingMalIds = array_diff($missingMalIds, $malBlackList); + // $missingMalIds = array_diff($missingMalIds, $malBlackList); // Add items on Anilist, but not Kitsu to Kitsu foreach($missingMalIds as $mid) @@ -338,10 +335,10 @@ final class SyncLists extends BaseCommand { { $malId = $kitsuItem['malId']; - if (\in_array((int)$malId, $malBlackList, TRUE)) + /* if (\in_array((int)$malId, $malBlackList, TRUE)) { continue; - } + } */ if (array_key_exists($malId, $anilistList)) { @@ -629,13 +626,25 @@ final class SyncLists extends BaseCommand { { $verb = ($action === 'update') ? 'updated' : 'created'; $this->echoBox("Successfully {$verb} Kitsu {$type} list item with id: {$id}"); + continue; } - else + + // Show a different message when you have an episode count mismatch + if (isset($responseData['errors'][0]['title'])) { - dump($responseData); - $verb = ($action === 'update') ? 'update' : 'create'; - $this->echoBox("Failed to {$verb} Kitsu {$type} list item with id: {$id}"); + $errorTitle = $responseData['errors'][0]['title']; + + if ($errorTitle === 'cannot exceed length of media') + { + $this->echoBox("Skipped Kitsu {$type} {$id} due to episode count mismatch with other API"); + continue; + } } + + dump($responseData); + $verb = ($action === 'update') ? 'update' : 'create'; + $this->echoBox("Failed to {$verb} Kitsu {$type} list item with id: {$id}"); + } } @@ -661,7 +670,15 @@ final class SyncLists extends BaseCommand { } else if ($action === 'create') { - $requester->addRequest($this->anilistModel->createFullListItem($item, $type)); + try + { + $requester->addRequest($this->anilistModel->createFullListItem($item, $type)); + } + catch (MissingIdException $e) + { + $id = $item['mal_id']; + $this->echoBox("Skipping Anilist ${type} with mal_id: {$id} due to missing mapping"); + } } }