From ba962f6053e35a2cde57dfb36b5a2cd717f89936 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Mon, 19 Dec 2022 15:36:37 +0300 Subject: [PATCH] Throw an error when we are unable to get access_token from plex api for the selected user. --- src/Backends/Plex/Action/GetUsersList.php | 2 +- src/Backends/Plex/PlexManage.php | 17 ++++++++++++----- src/Commands/Config/ManageCommand.php | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Backends/Plex/Action/GetUsersList.php b/src/Backends/Plex/Action/GetUsersList.php index 9035228d..5a8bbb88 100644 --- a/src/Backends/Plex/Action/GetUsersList.php +++ b/src/Backends/Plex/Action/GetUsersList.php @@ -128,7 +128,7 @@ final class GetUsersList ); } - $data['token'] = $tokenRequest->isSuccessful() ? $tokenRequest->response : 'Not found'; + $data['token'] = $tokenRequest->isSuccessful() ? $tokenRequest->response : null; } if (true === (bool)ag($opts, Options::RAW_RESPONSE)) { diff --git a/src/Backends/Plex/PlexManage.php b/src/Backends/Plex/PlexManage.php index 1b70cbbe..9e5abbf7 100644 --- a/src/Backends/Plex/PlexManage.php +++ b/src/Backends/Plex/PlexManage.php @@ -301,13 +301,20 @@ class PlexManage implements ManageInterface $backend = ag_delete($backend, 'options.' . Options::ADMIN_TOKEN); } - $userToken = ag($userInfo[$map[$user]], 'token'); - - // @TODO temp fix until we understand why plex sometimes does not report user token. - if ('not found' !== strtolower($userToken)) { - $backend = ag_set($backend, 'token', $userToken); + if (null === ($userToken = ag($userInfo[$map[$user]], 'token'))) { + $this->output->writeln( + r( + 'Unable to get [{user}] access_token. check the logs.', + [ + 'user' => $user + ] + ) + ); + return; } + $backend = ag_set($backend, 'token', $userToken); + return; } catch (Throwable $e) { $this->output->writeln('Failed to get the users list from backend.'); diff --git a/src/Commands/Config/ManageCommand.php b/src/Commands/Config/ManageCommand.php index 01deb4ba..9eecf62c 100644 --- a/src/Commands/Config/ManageCommand.php +++ b/src/Commands/Config/ManageCommand.php @@ -170,8 +170,6 @@ final class ManageCommand extends Command $u = ag(Config::get('supported'), $type)::manage($u); })(); - $output->writeln(''); - // -- $name.import.enabled (function () use ($input, $output, &$u) { $chosen = (bool)ag($u, 'import.enabled', true); @@ -180,7 +178,15 @@ final class ManageCommand extends Command $question = new ConfirmationQuestion( r( - 'Enable importing of metadata and play state from this backend? {default}' . PHP_EOL . '> ', + <<Enable watch/play state import from this backend? {default} + ------------------ + WARNING: If this backend is new and does not have your correct watch/play state, then you SHOULD + answer with no. If the date on movies/episodes is newer than your old backend watch date, it will + override the that state. Select no, and export your current play state and then re-nable the play state import. + ------------------ + Please read the FAQ about this subject. + HELP. PHP_EOL . '> ', [ 'default' => '[Y|N] [Default: ' . ($chosen ? 'Yes' : 'No') . ']', ] @@ -201,7 +207,7 @@ final class ManageCommand extends Command $question = new ConfirmationQuestion( r( - 'Enable exporting play state to this backend? {default}' . PHP_EOL . '> ', + 'Enable watch/play state export to this backend? {default}' . PHP_EOL . '> ', [ 'default' => '[Y|N] [Default: ' . ($chosen ? 'Yes' : 'No') . ']', ] @@ -231,7 +237,7 @@ final class ManageCommand extends Command $question = new ConfirmationQuestion( r( <<Enable Importing metadata ONLY from this backend? {default} + Enable metadata only import from this backend? {default} ------------------ To efficiently export to this backend we need relation map and this require us to get metadata from the backend. You have Importing disabled, as such this option @@ -240,7 +246,7 @@ final class ManageCommand extends Command This option will not alter your play state or add new items to the database. HELP. PHP_EOL . '> ', [ - 'default' => '[Y|N] [Default: ' . ($chosen ? 'Yes' : 'No') . ']', + 'default' => '[Y|N] [Default: ' . ($chosen ? 'Yes' : 'No') . ']', ] ), $chosen