More error checking
This commit is contained in:
parent
70eb4f11b3
commit
fafd75b791
@ -125,7 +125,10 @@ final class Model
|
|||||||
*/
|
*/
|
||||||
public function createListItem(array $data, string $type = 'anime'): ?Request
|
public function createListItem(array $data, string $type = 'anime'): ?Request
|
||||||
{
|
{
|
||||||
$createData = [];
|
if ($data['mal_id'] === NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
$mediaId = $this->getMediaIdFromMalId($data['mal_id'], mb_strtoupper($type));
|
$mediaId = $this->getMediaIdFromMalId($data['mal_id'], mb_strtoupper($type));
|
||||||
|
|
||||||
@ -134,6 +137,8 @@ final class Model
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$createData = [];
|
||||||
|
|
||||||
if ($type === 'ANIME')
|
if ($type === 'ANIME')
|
||||||
{
|
{
|
||||||
$createData = [
|
$createData = [
|
||||||
|
@ -869,9 +869,14 @@ final class Model {
|
|||||||
* @return Request
|
* @return Request
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function createListItem(array $data): Request
|
public function createListItem(array $data): ?Request
|
||||||
{
|
{
|
||||||
$data['user_id'] = $this->getUserIdByUsername($this->getUsername());
|
$data['user_id'] = $this->getUserIdByUsername($this->getUsername());
|
||||||
|
if ($data['id'] === NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->listItem->create($data);
|
return $this->listItem->create($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ use Aviat\AnimeClient\API\Anilist\Transformer\{
|
|||||||
AnimeListTransformer as AALT,
|
AnimeListTransformer as AALT,
|
||||||
MangaListTransformer as AMLT
|
MangaListTransformer as AMLT
|
||||||
};
|
};
|
||||||
|
use Aviat\AnimeClient\API\Anilist\Model as AnilistModel;
|
||||||
|
use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel;
|
||||||
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
|
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
|
||||||
use Aviat\AnimeClient\Types\FormItem;
|
use Aviat\AnimeClient\Types\FormItem;
|
||||||
use Aviat\Ion\Di\Exception\ContainerException;
|
use Aviat\Ion\Di\Exception\ContainerException;
|
||||||
@ -40,13 +42,13 @@ final class SyncLists extends BaseCommand {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for making requests to Anilist API
|
* Model for making requests to Anilist API
|
||||||
* @var \Aviat\AnimeClient\API\Anilist\Model
|
* @var AnilistModel
|
||||||
*/
|
*/
|
||||||
protected $anilistModel;
|
protected $anilistModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for making requests to Kitsu API
|
* Model for making requests to Kitsu API
|
||||||
* @var \Aviat\AnimeClient\API\Kitsu\Model
|
* @var KitsuModel
|
||||||
*/
|
*/
|
||||||
protected $kitsuModel;
|
protected $kitsuModel;
|
||||||
|
|
||||||
@ -602,6 +604,12 @@ final class SyncLists extends BaseCommand {
|
|||||||
}
|
}
|
||||||
else if ($action === 'create')
|
else if ($action === 'create')
|
||||||
{
|
{
|
||||||
|
$maybeRequest = $this->kitsuModel->createListItem($item);
|
||||||
|
if ($maybeRequest === NULL)
|
||||||
|
{
|
||||||
|
$this->echoBox("Skipped creating Kitsu {$type} due to missing id ¯\_(ツ)_/¯");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$requester->addRequest($this->kitsuModel->createListItem($item));
|
$requester->addRequest($this->kitsuModel->createListItem($item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -682,7 +690,6 @@ final class SyncLists extends BaseCommand {
|
|||||||
|
|
||||||
$responseData = Json::decode($response);
|
$responseData = Json::decode($response);
|
||||||
|
|
||||||
// $id = $itemsToUpdate[$key]['id'];
|
|
||||||
if ( ! array_key_exists('errors', $responseData))
|
if ( ! array_key_exists('errors', $responseData))
|
||||||
{
|
{
|
||||||
$verb = ($action === 'update') ? 'updated' : 'created';
|
$verb = ($action === 'update') ? 'updated' : 'created';
|
||||||
|
@ -63,9 +63,7 @@ abstract class AbstractType implements ArrayAccess, Countable {
|
|||||||
*/
|
*/
|
||||||
public function __isset($name): bool
|
public function __isset($name): bool
|
||||||
{
|
{
|
||||||
// This returns the expected results because unset
|
return property_exists($this, $name) && isset($this->$name);
|
||||||
// properties no longer exist on the class
|
|
||||||
return property_exists($this, $name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user