From 42ac2136a48a1920db265cf05b238e5c368e4657 Mon Sep 17 00:00:00 2001 From: tracer Date: Sat, 22 Jan 2022 18:52:17 +0100 Subject: [PATCH] changed exit code if error Signed-off-by: tracer --- bindAPI/src/Controller/BindAPI.php | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bindAPI/src/Controller/BindAPI.php b/bindAPI/src/Controller/BindAPI.php index 90029dc..e3b946b 100755 --- a/bindAPI/src/Controller/BindAPI.php +++ b/bindAPI/src/Controller/BindAPI.php @@ -11,12 +11,9 @@ error_reporting(E_ALL); // 61e6ce5dd8a1b.bc1c314ce364f6878084c254fe4c6345801c43a49bb8eb71 - use LucidFrame\Console\ConsoleTable; -use PDO; use UnhandledMatchError; - if (php_sapi_name() !== 'cli') { exit; } @@ -46,15 +43,17 @@ class BindAPI /** * @param bool|array $panel * - * @return void + * @return bool */ - public function checkPing(bool|array $panel): void + public function checkPing(bool|array $panel): Bool { + $error = false; + $a = $panel['a'] ?? ''; print(COLOR_YELLOW . $panel['name']); if (!empty($a)) { if ($this->checkController->sendCommand(serverName: $panel['name'], versionIP: 4, apiKey: $panel['apikey'], command: 'ping')) { - // if verbose … + // TODO if verbose … print(COLOR_DEFAULT . ' ' . $panel['a'] . ': ' . COLOR_GREEN . 'pong'); } else { $error = true; @@ -69,6 +68,7 @@ class BindAPI $error = true; } } + return $error; } @@ -195,21 +195,28 @@ class BindAPI function handlePanelsAPIPing() { $error = false; + $id = $this->argv[2] ?? 0; if ($id != 0) { $panel = $this->panelController->findByID($id); - $this->checkPing($panel); + if (!$this->checkPing($panel)) { + $error = true; + } } else { $panels = $this->panelController->findAll(); foreach ($panels as $panel) { - $this->checkPing(panel: $panel); + if (!$this->checkPing(panel: $panel)) { + $error = true; + } } } - - - - print(PHP_EOL); + echo PHP_EOL; + if ($error) { + exit(1); + } else { + exit(0); + } }