From fc62a5cd34818ce0dc9b77f22925fa412ebb3d00 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Mon, 18 Mar 2024 19:47:51 +0300 Subject: [PATCH] Added live-ness test for plex server when chosen at config:manage --- src/Backends/Plex/PlexManage.php | 37 +++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Backends/Plex/PlexManage.php b/src/Backends/Plex/PlexManage.php index ba91a7c5..f8c029b3 100644 --- a/src/Backends/Plex/PlexManage.php +++ b/src/Backends/Plex/PlexManage.php @@ -149,6 +149,23 @@ class PlexManage implements ManageInterface if (true === ag_exists($map, $server)) { $backend = ag_set($backend, 'url', ag($map, $server)); $backend = ag_set($backend, 'uuid', ag($uuid, $server)); + + try { + $this->output->writeln( + r( + 'Successfully contacted the Backed. It responded with [{version}] as it\'s version.', + [ + 'version' => makeBackend(ag_set($backend, 'user', '1'))->getVersion() + ] + ) + ); + } catch (Throwable $e) { + $this->output->writeln(r('Unable to contact [{url}]. {error}', [ + 'url' => ag($backend, 'url'), + 'error' => $e->getMessage() + ])); + goto re_select; + } return; } } @@ -180,12 +197,13 @@ class PlexManage implements ManageInterface $chosen ); - $question->setValidator(function ($answer) { + $question->setValidator(function ($answer) use ($backend) { if (false === isValidURL($answer)) { throw new RuntimeException( 'Invalid URL was selected/given. Expecting something like http://plex:32400.' ); } + return $answer; }); @@ -195,6 +213,23 @@ class PlexManage implements ManageInterface goto re_select; } + try { + $this->output->writeln( + r( + 'Successfully contacted the Backed. It responded with [{version}] as it\'s version.', + [ + 'version' => makeBackend(ag_set(ag_set($backend, 'url', $url), 'user', '1'))->getVersion() + ] + ) + ); + } catch (Throwable $e) { + $this->output->writeln(r('Unable to contact {url}. {error}', [ + 'url' => $url, + 'error' => $e->getMessage() + ])); + goto re_select; + } + $backend = ag_set($backend, 'url', $url); })(); $this->output->writeln('');