From 238a42380621dd206a56bfe14ce1a56bcfc050f7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 7 Oct 2020 15:30:42 -0400 Subject: [PATCH] Fix updating anime status when certain fields are empty --- app/views/anime/edit.php | 2 +- src/AnimeClient/API/Kitsu/ListItem.php | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/views/anime/edit.php b/app/views/anime/edit.php index 500f777d..6d9a8ff2 100644 --- a/app/views/anime/edit.php +++ b/app/views/anime/edit.php @@ -32,7 +32,7 @@ diff --git a/src/AnimeClient/API/Kitsu/ListItem.php b/src/AnimeClient/API/Kitsu/ListItem.php index d3db19b2..258bf108 100644 --- a/src/AnimeClient/API/Kitsu/ListItem.php +++ b/src/AnimeClient/API/Kitsu/ListItem.php @@ -143,16 +143,27 @@ final class ListItem extends AbstractListItem { */ public function update(string $id, FormItemData $data): Request { - return $this->requestBuilder->mutateRequest('UpdateLibraryItem', [ + // Data to always send + $updateData = [ 'id' => $id, 'notes' => $data['notes'], 'private' => (bool)$data['private'], - 'progress' => (int)$data['progress'], - 'ratingTwenty' => (int)$data['ratingTwenty'], 'reconsumeCount' => (int)$data['reconsumeCount'], 'reconsuming' => (bool)$data['reconsuming'], 'status' => strtoupper($data['status']), - ]); + ]; + + // Only send these variables if they have a value + if ($data['progress'] !== NULL) + { + $updateData['progress'] = (int)$data['progress']; + } + if ($data['ratingTwenty'] !== NULL) + { + $updateData['ratingTwenty'] = (int)$data['ratingTwenty']; + } + + return $this->requestBuilder->mutateRequest('UpdateLibraryItem', $updateData); } /**