From d1987fc710b3ec4908fc977f67d682735e96c622 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 10 Jan 2018 16:18:06 -0500 Subject: [PATCH] Handle syncing errors more consistently --- composer.json | 4 ++-- src/Command/SyncKitsuWithMal.php | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 7f13f0ca..4192c657 100644 --- a/composer.json +++ b/composer.json @@ -41,9 +41,9 @@ "robmorgan/phinx": "^0.9.1", "sebastian/phpcpd": "^3.0", "spatie/phpunit-snapshot-assertions": "^1.2.0", - "squizlabs/php_codesniffer": "^3.0.0@beta", + "squizlabs/php_codesniffer": "^3.2.2", "symfony/var-dumper": "^4.0.1", - "theseer/phpdox": "^0.10.1", + "theseer/phpdox": "^0.11.0", "filp/whoops": "^2.1" }, "scripts": { diff --git a/src/Command/SyncKitsuWithMal.php b/src/Command/SyncKitsuWithMal.php index c4638bc5..d97b6e5f 100644 --- a/src/Command/SyncKitsuWithMal.php +++ b/src/Command/SyncKitsuWithMal.php @@ -49,7 +49,7 @@ class SyncKitsuWithMal extends BaseCommand { protected $malModel; /** - * Run the image conversion script + * Run the Kitsu <=> MAL sync script * * @param array $args * @param array $options @@ -112,7 +112,6 @@ class SyncKitsuWithMal extends BaseCommand { if ( ! empty($data['updateKitsu'])) { - // print_r($data['updateKitsu']); $count = count($data['updateKitsu']); $this->echoBox("Updating {$count} outdated Kitsu {$type} list items"); $this->updateKitsuListItems($data['updateKitsu'], $type); @@ -467,14 +466,16 @@ class SyncKitsuWithMal extends BaseCommand { foreach($responses as $key => $response) { + $responseData = Json::decode($response); + $id = $itemsToUpdate[$key]['id']; - if ($response->getStatus() === 200) + if ( ! array_key_exists('errors', $responseData)) { $this->echoBox("Successfully updated Kitsu {$type} list item with id: {$id}"); } else { - echo $response->getBody(); + dump($responseData); $this->echoBox("Failed to update Kitsu {$type} list item with id: {$id}"); } } @@ -495,7 +496,7 @@ class SyncKitsuWithMal extends BaseCommand { foreach($responses as $key => $response) { $id = $itemsToUpdate[$key]['mal_id']; - if ($response->getBody() === 'Updated') + if ($response === 'Updated') { $this->echoBox("Successfully updated MAL {$type} list item with id: {$id}"); } @@ -518,14 +519,17 @@ class SyncKitsuWithMal extends BaseCommand { foreach($responses as $key => $response) { + $responseData = Json::decode($response); + $id = $itemsToAdd[$key]['id']; - if ($response->getStatus() === 201) + + if ( ! array_key_exists('errors', $responseData)) { $this->echoBox("Successfully created Kitsu {$type} list item with id: {$id}"); } else { - echo $response->getBody(); + dump($responseData); $this->echoBox("Failed to create Kitsu {$type} list item with id: {$id}"); } } @@ -547,7 +551,7 @@ class SyncKitsuWithMal extends BaseCommand { foreach($responses as $key => $response) { $id = $itemsToAdd[$key]['mal_id']; - if ($response->getBody() === 'Created') + if ($response === 'Created') { $this->echoBox("Successfully created MAL {$type} list item with id: {$id}"); } @@ -557,4 +561,4 @@ class SyncKitsuWithMal extends BaseCommand { } } } -} \ No newline at end of file +}