Show fewer sync errors by filtering common data disparity issues

This commit is contained in:
Timothy Warren 2019-07-11 16:38:21 -04:00
parent ea5eb21941
commit c5bb555695
3 changed files with 58 additions and 17 deletions

View File

@ -0,0 +1,19 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.1
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @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 {}

View File

@ -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);

View File

@ -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']))
{
$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}");
}
}
}
@ -660,9 +669,17 @@ final class SyncLists extends BaseCommand {
);
}
else if ($action === 'create')
{
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");
}
}
}
$responses = $requester->makeRequests();