From: Marcin Haba Date: Thu, 2 Nov 2023 07:25:12 +0000 (+0100) Subject: baculum :Split client overview endpoint into reachable and unreachable clients X-Git-Tag: Beta-15.0.1~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46cf898c6dfae7b5096a944a8e182f12a40ddcbb;p=thirdparty%2Fbacula.git baculum :Split client overview endpoint into reachable and unreachable clients --- diff --git a/gui/baculum/protected/API/Modules/Database.php b/gui/baculum/protected/API/Modules/Database.php index 78528ccbb..3397b9725 100644 --- a/gui/baculum/protected/API/Modules/Database.php +++ b/gui/baculum/protected/API/Modules/Database.php @@ -211,6 +211,14 @@ class Database extends APIModule { $cond[] = "{$key} {$value[$i]['operator']} :{$kval}{$i}"; $vals[":{$kval}{$i}"] = $value[$i]['vals']; $value[$i]['operator'] = ''; + } elseif ($value[$i]['operator'] == '=') { + $cond[] = "$key = :{$kval}{$i}"; + $vals[":{$kval}{$i}"] = $value[$i]['vals']; + $value[$i]['operator'] = ''; + } elseif ($value[$i]['operator'] == '!=') { + $cond[] = "$key != :{$kval}{$i}"; + $vals[":{$kval}{$i}"] = $value[$i]['vals']; + $value[$i]['operator'] = ''; } else { $cond[] = "$key = :{$kval}{$i}"; $vals[":{$kval}{$i}"] = $value[$i]['vals']; diff --git a/gui/baculum/protected/API/Pages/API/Clients.php b/gui/baculum/protected/API/Pages/API/Clients.php index 59fa0c37b..eaffe5734 100644 --- a/gui/baculum/protected/API/Pages/API/Clients.php +++ b/gui/baculum/protected/API/Pages/API/Clients.php @@ -132,14 +132,54 @@ class Clients extends BaculumAPIServer { $sort = [[$order_by_lc, $order_direction]]; } - $clients = $this->getModule('client')->getClients( - $limit, - $offset, - $sort, - $params, - $jobs, - $mode - ); + $clients = []; + if ($mode == ClientManager::CLIENT_RESULT_MODE_OVERVIEW) { + if (!in_array('Client.Uname', $params)) { + $params['Client.Uname'] = []; + } + + // reachable clients (uname exists) + $params['Client.Uname'][] = [ + 'operator' => '!=', + 'vals' => '' + ]; + $clients_reached = $this->getModule('client')->getClients( + $limit, + $offset, + $sort, + $params, + $jobs, + $mode + ); + + // unreachable clients (uname not exists) + array_pop($params['Client.Uname']); + $params['Client.Uname'][] = [ + 'operator' => '=', + 'vals' => '' + ]; + $clients_unreached = $this->getModule('client')->getClients( + $limit, + $offset, + $sort, + $params, + $jobs, + $mode + ); + $clients = [ + 'reachable' => $clients_reached, + 'unreachable' => $clients_unreached + ]; + } else { + $clients = $this->getModule('client')->getClients( + $limit, + $offset, + $sort, + $params, + $jobs, + $mode + ); + } $this->output = $clients; $this->error = ClientError::ERROR_NO_ERRORS; } else {