Throw an error when we are unable to get access_token from plex api for the selected user.

This commit is contained in:
Abdulmhsen B. A. A
2022-12-19 15:36:37 +03:00
parent 0b1528ffe9
commit ba962f6053
3 changed files with 25 additions and 12 deletions

View File

@@ -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)) {

View File

@@ -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(
'<error>Unable to get [{user}] access_token. check the logs.</error>',
[
'user' => $user
]
)
);
return;
}
$backend = ag_set($backend, 'token', $userToken);
return;
} catch (Throwable $e) {
$this->output->writeln('<error>Failed to get the users list from backend.</error>');

View File

@@ -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(
'<question>Enable importing of <flag>metadata</flag> and <flag>play state</flag> from this backend</question>? {default}' . PHP_EOL . '> ',
<<<HELP
<question>Enable <flag>watch/play state</flag> import from this backend</question>? {default}
------------------
<notice>WARNING:</notice> If this backend is new and does not have your correct watch/play state, then you <error>SHOULD</error>
answer with <value>no</value>. If the date on movies/episodes is newer than your old backend watch date, it will
override the that state. Select <value>no</value>, and export your current play state and then re-nable the play state import.
------------------
<value>Please read the FAQ about this subject.</value>
HELP. PHP_EOL . '> ',
[
'default' => '[<value>Y|N</value>] [<value>Default: ' . ($chosen ? 'Yes' : 'No') . '</value>]',
]
@@ -201,7 +207,7 @@ final class ManageCommand extends Command
$question = new ConfirmationQuestion(
r(
'<question>Enable exporting <value>play state</value> to this backend</question>? {default}' . PHP_EOL . '> ',
'<question>Enable <value>watch/play state</value> export to this backend</question>? {default}' . PHP_EOL . '> ',
[
'default' => '[<value>Y|N</value>] [<value>Default: ' . ($chosen ? 'Yes' : 'No') . '</value>]',
]
@@ -231,7 +237,7 @@ final class ManageCommand extends Command
$question = new ConfirmationQuestion(
r(
<<<HELP
<question>Enable Importing <info>metadata ONLY</info> from this backend</question>? {default}
<question>Enable <value>metadata</value> only import from this backend</question>? {default}
------------------
To efficiently <cmd>export</cmd> to this backend we need relation map and this require
us to get metadata from the backend. You have <cmd>Importing</cmd> disabled, as such this option
@@ -240,7 +246,7 @@ final class ManageCommand extends Command
<value>This option will not alter your play state or add new items to the database.</value>
HELP. PHP_EOL . '> ',
[
'default' => '[Y|N] [Default: ' . ($chosen ? 'Yes' : 'No') . ']',
'default' => '[<value>Y|N</value>] [<value>Default: ' . ($chosen ? 'Yes' : 'No') . '</value>]',
]
),
$chosen