Some syncing cleanup
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2020-08-24 13:10:43 -04:00
parent 40a340c67c
commit 26a1c464a1
3 changed files with 22 additions and 11 deletions

View File

@ -655,7 +655,7 @@ final class SyncLists extends BaseCommand {
$return['data'] = $update; $return['data'] = $update;
$return['updateType'] = array_unique($return['updateType']); $return['updateType'] = array_unique($return['updateType']);
// Fill in missing data values for update on Anlist // Fill in missing data values for update
// so I don't have to create a really complex graphql query // so I don't have to create a really complex graphql query
// to handle each combination of fields // to handle each combination of fields
if ($return['updateType'][0] === API::ANILIST) if ($return['updateType'][0] === API::ANILIST)
@ -672,6 +672,22 @@ final class SyncLists extends BaseCommand {
$return['data']['data'] = array_merge($prevData, $return['data']['data']); $return['data']['data'] = array_merge($prevData, $return['data']['data']);
} }
else if ($return['updateType'][0] === API::KITSU)
{
$prevData = [
'notes' => $anilistItem['data']['notes'],
'private' => $anilistItem['data']['private'],
'progress' => $anilistItem['data']['progress'] ?? 0,
'rating' => (((int)$anilistItem['data']['rating']) > 0)
? $anilistItem['data']['rating'] / 5
: 0,
'reconsumeCount' => $anilistItem['data']['reconsumeCount'],
'reconsuming' => $anilistItem['data']['reconsuming'],
'status' => $anilistItem['data']['status'],
];
$return['data']['data'] = array_merge($prevData, $return['data']['data']);
}
return $return; return $return;
} }
@ -718,6 +734,7 @@ final class SyncLists extends BaseCommand {
$responseData = Json::decode($response); $responseData = Json::decode($response);
$id = $itemsToUpdate[$key]['id']; $id = $itemsToUpdate[$key]['id'];
$mal_id = $itemsToUpdate[$key]['mal_id'];
if ( ! array_key_exists('errors', $responseData)) if ( ! array_key_exists('errors', $responseData))
{ {
$verb = ($action === SyncAction::UPDATE) ? 'updated' : 'created'; $verb = ($action === SyncAction::UPDATE) ? 'updated' : 'created';
@ -743,7 +760,7 @@ final class SyncLists extends BaseCommand {
'responseData' => $responseData, 'responseData' => $responseData,
]); ]);
$verb = ($action === SyncAction::UPDATE) ? SyncAction::UPDATE : SyncAction::CREATE; $verb = ($action === SyncAction::UPDATE) ? SyncAction::UPDATE : SyncAction::CREATE;
$this->echoError("Failed to {$verb} Kitsu {$type} list item with id: {$id}"); $this->echoError("Failed to {$verb} Kitsu {$type} list item with id: {$id}, and mal_id: {$mal_id}");
} }
} }

View File

@ -285,6 +285,7 @@ class Controller {
'title' => $title, 'title' => $title,
'message' => $message, 'message' => $message,
], NULL, 404); ], NULL, 404);
exit();
} }
/** /**

View File

@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model;
use Aviat\AnimeClient\API\Anilist\Model as AnilistModel; use Aviat\AnimeClient\API\Anilist\Model as AnilistModel;
use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel; use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel;
use Aviat\AnimeClient\API\Kitsu\Transformer\LibraryEntryTransformer;
use Aviat\AnimeClient\API\ParallelAPIRequest; use Aviat\AnimeClient\API\ParallelAPIRequest;
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus; use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
use Aviat\AnimeClient\Types\{ use Aviat\AnimeClient\Types\{
@ -159,15 +160,7 @@ class Anime extends API {
*/ */
public function getLibraryItem(string $itemId): AnimeListItem public function getLibraryItem(string $itemId): AnimeListItem
{ {
$item = $this->kitsuModel->getListItem($itemId); return $this->kitsuModel->getListItem($itemId);
$array = $item->toArray();
if (is_array($array['notes']))
{
$array['notes'] = '';
}
return AnimeListItem::from($array);
} }
/** /**